rgbcof
asked on
Perl, floor and ceiling a floating number
$floatnum = "1234.5678";
# I want to floor the number to 3rd digit after the decimal. So 1234.567
# also, ceiling it to: 1234.568
# I want to floor the number to 3rd digit after the decimal. So 1234.567
# also, ceiling it to: 1234.568
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Doesn't take care of all case. I will post a different question.
Too bad I had a solution for you but got busy and you closed it :(
use POSIX;
$floatnum = "1234.5678";
$floor=floor($floatnum*100 0)/1000;
$ceiling=ceil($floatnum*10 00)/1000;
#note that neither 1234.567 nor 1234.568 can be represented exactly in IEEE floating point
$floatnum = "1234.5678";
$floor=floor($floatnum*100
$ceiling=ceil($floatnum*10
#note that neither 1234.567 nor 1234.568 can be represented exactly in IEEE floating point
ASKER
# the ceiling doesn't work if the last digit is less than 5.
# ceiling should be 1234.568