Hi Guys, The original code below would output a number with 2 or four decimal places. (str_replace(',', '', $row['price']) * 1.1 ) . "\n"; Code (markup): What I need to do is round it up/down to 2 decimal places. I tried the below code and it was a disaster, it displays a number that was 3438.545 as 3.30 number_format(str_replace(',$', '', $row['price']) * 1.1, 2, '.', '' ) . "\n"; Code (markup): Any ideas on where I am going wrong? What I want it to show is 3438.55 The "*1.1" is a tax calculation, I also had to strip a , and a $ from the numbers.
Perhaps: round(intval($row['price']) * 1.1, 2); PHP: ?? If not, can you show me an example of what $row['price'] holds?
string number_format ( float number [, int decimals [, string dec_point, string thousands_sep]] ) number format is used to show number grouped in thousands. if you want to show a number as a variable, you might wanna look at sprintf which formats your given number to any type you like. then output the result with number format to show correctly placed dots and commas using your locale.
The problem was in your str_replace, you are trying to replace ",$" together and not separately. str_replace(array(',', '$'), '', $row['price']) PHP: