Hello, Jennifer

are you still struggling with the trailing zeros?
Then try, 
    echo round($number, 2); // with ie.: $number = 123.45 and 123.00

As I know there is no particular float, but double type in PHP.

(double means "double precision number" -- ie.: 15 decimal places instead of 6 decimal 
places or something like that -
, and therefore a 'double' consumes twice the space that 'float' does - in compiled 
languages such as C (8 bytes vs 4 bytes). 
So doubles and floats is closely related to the hardware representation. 
This is why "real" programming languages usually deal with floats and doubles.

Decimal (or numeric) comes from an another domain of computer science, namely database 
systems.
Decimal is a completely different approach of representing numbers, dealing with 
precision as commonly used in daily life, ie .: cents or gramms (as you wish in your 
shopping cart class). In a DBMS the storage space never does matter,
it focuses the ease of use and "readability".
You can specify how many digits are for storing the integer part and how many the 
fraction part of a number. In other words, this means that you *can specify* the 
maximum storable number (respect the whole number of digits) and minimal resolution / 
granulation (respect to number of fraction digits).

I hope this helps,

Papp Gyozo 
- [EMAIL PROTECTED]

ps.: my english is not so good, but i hope, you can understand what i was talking 
about.

----- Original Message ----- 
From: "Jennifer" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: 2001. május 4. 07:39
Subject: Re: [PHP] Working with numbers


> 
> 
> Christian Reiniger wrote:
> > 
> > On Thursday 03 May 2001 08:53, Jennifer wrote:
> > 
> > > I have a shopping cart that allows decimal points for quantities.
> > > I like it like that, but would like to remove any trailing zeros
> > > and if the quantity is not a fraction I would like to remove the
> > > decimal point too.
> > >
> > > What would be the easiest way to do this?  I don't see any
> > > function that would make it easy.
> > 
> > It's so easy that you don't need a function for it :)
> > 
> > $Qty = "12.470";
> > $Qty_real = (double) $Qty;
> > 
> > echo "$Qty - $Qty_real";
> > 
> > In other words - convert it from a strin to a floating-point number and
> > PHP will do the rest.
> 
> 
> I've done some searching on the php site for more info about
> double and float etc, but I don't really understand anything I
> found.  Can someone give me an explanation about the difference
> between decimal, float, double?
> 
> Should I be using decimal as my column type in the MySQL database
> or should I be using a different column type?
> 
> Jennifer
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to