tags:

views:

46

answers:

3
$value = '100.00';

echo $value * 100/100;

Or should I be rounding incase there's a value such as '100.70'? I'm displaying this for a table that displays daily rates, the total value contains the digits so I assume the user won't have to really worry about decimal values...

+1  A: 
echo $value * 100/100;

is equal to $value * 1 kind sir

Use number format to format your numbers instead of doing some fancy arithmetic

lemon
+2  A: 

Whether or not you should round is up to you. But for this consider using sprintf().

$value = '100.00';
echo sprintf("%.0f', $value);

is much better than some arithmetic hack to achieve the same thing. Also, multiplying then dividing by 100 is like multiplying by 1.

Depending on what you want to achieve exactly, number_format() or even money_format() may be options as well.

To do the actual rounding use round():

$value = '100.00';
echo round($value);
cletus
How would you do it personally?
meder
I, personally, would round anything greater than .50 up to the next dollar.
NTDLS
A: 

Usually, people looking at columns of money want to see them all formatted the same way. With different values, the second expression would 100.01 100.1 100 instead of 100.01 100.10 100.00.

There are several ways to format numbers, including format_number, sprintf(), and simple string manipulation.

wallyk