Possible Duplicate:
Truncate Decimal number not Round Off in jquery
I have values like 5.3777777, 4.6666666 on my Y variable.
How can I truncate it so it shows 5.3 or 5.6 instead with JavaScript?
Thanks in advance!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The standard way to do this in any language is to multiple the value by the inverse of the precision required, truncate, and then divide again:
If you want strict rounding rather than truncation then Javascript also has
Number.toFixed()built-in which does this for you.