|
#1
|
|||
|
|||
|
I've got some simple math code that rounds numbers to the second decimal place. ( $x + $y) = $z round($z, 2)
when it rounds to a number with a zero in the second decimal place it doesn't pad it. How do i fix that? I want the zero to stay on the end. IE: 5.204 would round to 5.20 but the code drops the last 0 and displays 5.2 Thanks for you help! |
|
#2
|
||||
|
||||
|
Padding is for strings.
But I googled it for you: http://www.htmlite.com/php011.php all about formatting numbers. |
|
#3
|
|||
|
|||
|
Did you try casting the variable as a float?
|
|
#4
|
||||
|
||||
|
Quote:
Quote:
But if yours is the most common reason for showing the zero with two decimal places--to display U.S. money quantities--you could instead use PHP: money_format - Manual which in my limited experience is the best way to deal with money stuff. The variable stays a string, displays correctly, and is sort of the PHP equivalent of the spreadsheet and database vartype "money". Remember, if you do this, you MUST specify a valid locale. The linked manual page tells all. |
|
#5
|
|||
|
|||
|
If you are working with money as the rounded number use money_format or if you are working with regular numbers use number_format.
__________________
http://www.anothertakestudios.com |
|
#6
|
||||
|
||||
|
Quote:
Code:
<?php
$first_number = 10;
$second_number = 3;
$total_sum = $first_number + $second_number;
printf ("%01.2f", $total_sum);
?>
13.00 |
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| quick question | nfrederick | Pre-Sales Questions | 8 | 03-07-2008 06:34 PM |
| Hey quick question | Private_Ale | Pre-Sales Questions | 2 | 12-07-2007 09:24 PM |
| Quick DNS question | iamaelephant | Pre-Sales Questions | 7 | 06-01-2007 06:49 PM |
| Quick question | hxc | Shared Hosting Support | 2 | 02-28-2007 09:41 AM |
| Quick question | Grumpy | Shared Hosting Support | 3 | 02-05-2005 12:02 PM |
All times are GMT -5. The time now is 02:42 AM.










