# Calculate till 2 decimals

3 replies to this topic

### #1 xoluz

xoluz
• New Members
• Newbie
• 7 posts

Posted 19 March 2006 - 09:19 AM

Hey there!

How can I calculate till 2 decimals after the comma?

I've got something like this now

```\$price1 = array_sum(\$prices);
\$test = \$price1 * 0.7;
echo \$test;
```

Now I'm getting values like 32.233 or 500.300, but they should be 32,23 and 500,30 :s

### #2 akitchin

akitchin
• Staff Alumni
• 2,516 posts
• LocationCalgary, AB, Canada

Posted 19 March 2006 - 09:40 AM

round(\$value, 2)

look it up in the manual for more info and similar functions.

### #3 xoluz

xoluz
• New Members
• Newbie
• 7 posts

Posted 19 March 2006 - 09:43 AM

tnx ill check it out

### #4 Barand

Barand
• Moderators
• Sen . ( ile || sei )
• 18,016 posts

Posted 19 March 2006 - 11:01 AM

Also, have a look at [a href=\"http://www.php.net/number_format\" target=\"_blank\"]number_format() function[/a]

eg

```\$test = 32.4567;

echo number_format(\$test, 2, ',', '');```

--> 32,46
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.