• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
rounding a decimal

#8
[eluser]linuxbz[/eluser]
@batteries - thanks.

Also, to display 3.30 rather than 3.3 try this:

Code:
$y = 5.9999;  // number to round down
$p = 2;  // number of decimals
$n = pow(10,$p);  // multiplier and divisor
$x = sprintf("#01.${p}f", floor($y*$n/$n));  // result is a string

which could be made into a function if needed more than once.

Edit: replace the # with % in the sprintf function above ... forum software wouldn't allow a % there apparently.


Messages In This Thread
rounding a decimal - by El Forum - 07-02-2007, 08:42 PM
rounding a decimal - by El Forum - 07-02-2007, 10:41 PM
rounding a decimal - by El Forum - 07-02-2007, 11:20 PM
rounding a decimal - by El Forum - 07-02-2007, 11:28 PM
rounding a decimal - by El Forum - 07-02-2007, 11:31 PM
rounding a decimal - by El Forum - 07-03-2007, 12:23 AM
rounding a decimal - by El Forum - 07-03-2007, 12:54 AM
rounding a decimal - by El Forum - 07-03-2007, 06:32 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.