PDA

View Full Version : cut decimal places


ckey
03-06-2003, 08:44 AM
Hi,
a perhaps basic question. I am getting some values of variables like 3.1, 3.7, 3.9 etc. Now I want to cut the decimal places to get 3 in this case. Or 2 for 2.0 to 2.9. How can I do this?

Thanks in advance

pom
03-06-2003, 09:34 AM
Math.floor(). For your information, Math.ceil() and Math.round() also exist.

pom :)

ckey
03-06-2003, 09:58 AM
thanks, a lot. Should have find this on my own :)

annexion
03-07-2003, 01:02 AM
function rounder(input, places, currency) {
if (currency) {
return (["$"+(Math.round(input*Math.pow(10, places))/Math.pow(10, places))]);
} else {
return (Math.round(input*Math.pow(10, places))/Math.pow(10, places));
}
}
var_to_round = 234.2398476;
output = rounder(var_to_round, 2, true);

Here's something I made up in two seconds. Play around.

Good luck.

CyanBlue
03-07-2003, 04:27 AM
Good job, bro... ;)

Wow... 337 characters in two seconds??? Wow... :p

annexion
03-07-2003, 07:22 PM
:p I love you man.

Rhino
10-17-2006, 09:40 PM
Very nice, man. You saved me some hassle and tears.

-Rhino

colfaxrev
10-17-2006, 11:52 PM
Math.floor(). For your information, Math.ceil() and Math.round() also exist.

pom :)

nice signarture POM!!!!

01001001 01110100 00100000 01101101 01100001 01101011 01100101 01110011 00100000 01101101 01100101 00100000 01110100 01101000 01101001 01101110 01101011 00100000 01101111 01100110 00100000 01000001 01110101 01110011 01110100 01101001 01101110 00100000 01010000 01101111 01110111 01100101 01110010 01110011 00100001