[PHP] Working with numbers

2001-05-09 Thread Gerry

Could you suggest a function for displaying decimal zeros.

For example I have this:
$num = 2.00;
$num2 = 3.00;
$result = $num + $num2;
echo $result;

I get 5 but not 5.00


Anyone outhere?

Thanks in advance!

Gerry Figueroa

-- 
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]




Re: [PHP] Working with numbers

2001-05-09 Thread Reuben D Budiardja

Use number_format() function.

See http://www.php.net/manual/en/function.number-format.php for detail.

Reuben D. B

At 11:22 AM 5/9/01 -0700, Gerry wrote:
Could you suggest a function for displaying decimal zeros.

For example I have this:
$num = 2.00;
$num2 = 3.00;
$result = $num + $num2;
echo $result;

I get 5 but not 5.00


Anyone outhere?

Thanks in advance!

Gerry Figueroa

--
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]




Re: [PHP] Working with numbers

2001-05-09 Thread Christian Dechery

At 11:22 9/5/2001 -0700, Gerry wrote:
Could you suggest a function for displaying decimal zeros.

For example I have this:
$num = 2.00;
$num2 = 3.00;
$result = $num + $num2;
echo $result;

I get 5 but not 5.00

try $result = (float)$num + (float)$num2;


-- 
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]




Re: [PHP] Working with numbers

2001-05-04 Thread Gyozo Papp

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]




[PHP] Working with numbers

2001-05-03 Thread Jennifer

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.

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]




Re: [PHP] Working with numbers

2001-05-03 Thread Christian Reiniger

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.

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

Drink wet cement. Get stoned.

--
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]




Re: [PHP] Working with numbers

2001-05-03 Thread Gyozo Papp

what about function round() with precision argument ?

check it:

for ($i = 0; $i  10; $i += 0.25) {
   echo round($i,2). br;
}

- Original Message - 
From: Jennifer [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: 2001. május 3. 08:53
Subject: [PHP] Working with numbers


 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.
 
 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]




Re: [PHP] Working with numbers

2001-05-03 Thread Oliver Heinisch

At 01:39 04.05.01 -0400, you wrote:
Ok Jennifer lets do some basics ;-)
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?

decimal is a straight number f.e 123456 the size/length of this number 
belongs to the used hardware/compiler (normally 64bit???)
it could be signed so it could be -123456 or +123456
float is a number like 123,456 or 0,123456 size/signed  see above
double is also a number like float but with the double size (normally 128 
bit ??)


Should I be using decimal as my column type in the MySQL database
or should I be using a different column type?

If you want to store float numbers like prices or so you could use 
float(M,D) where M ist the langth of all numbers
and D is the number of the fraction(is that word right) I mean what´s 
behind the , .
Look in the manual of mysql datatypes to get more information about 
numbers and other interesting
datatypes.
HTH Oliver




--
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]