PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Float Value Parse Problem
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Float Value Parse Problem

Réponse
 
LinkBack Outils de la discussion
Vieux 07/01/2008, 11h20   #1
Cyril Chacko
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Float Value Parse Problem

Hi,

I have created a class and passing a float value to a method in it. I
have checked the the argument values in the method. The passed
argument has the proper value. However, on any arithmetic operation
the float as a whole is rounded off.

System Information :
Operating System : Windows
PHP Version : PHP Version 5.2.4
Web Server : Microsoft-IIS/5.0

Code Snippet :
<?php

class Order extends JObject {
var $_name = 'Order';
var $id = null;
var $ord_desc = null;
var $date = null;
var $total_amt = 0;
var $scheme = null;
var $shipping = 0.00;
var $service_tax = 0.00;
var $other = 0.00;
var $discount = 0.00;
var $discount_percentage = 0.00;
var $qty = 0;
var $uid = 0;
var $payment_mode = 0;
var $deliverydt = null;
var $paymentstatus = 0;
var $_amount = 0.00;
var $recordstatus = 0;

function addItem( $qty, $price, $discount = 0 ) {
$this->qty += $qty;
$this->total_amt += ( $price * $qty )- $discount;
return true;
}

}
?>

-----
On Caliing the function as
$order->addItem( 1, 2555.00, 0 );
$price = 2555.00, String Data Type
$price * $qty = 3000, Double Data Type

$order->addItem( 1, 3005.00, 0 );
$price = 3005.00, String Data Type
$price * $qty = 3000, Double Data Type

Please let me know if anything else is required. Thanks for the .

Regards.

Cyril Chacko
--
Beauty lies in the eye of the beholder. Make sure they are on you.
  Réponse avec citation
Vieux 08/01/2008, 02h21   #2
Chris
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Float Value Parse Problem

Cyril Chacko wrote:
> Hi,
>
> I have created a class and passing a float value to a method in it. I
> have checked the the argument values in the method. The passed
> argument has the proper value. However, on any arithmetic operation
> the float as a whole is rounded off.


http://php.net/float

There is a message there about precision problems.

--
Postgresql & php tutorials
http://www.designmagick.com/
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h47.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15631 seconds with 10 queries