I want the exact 2 digits after the decimal point. I tried the toFixed(2)
function but it returns rounded off 2 digits. Here is my Code it returns 18.70
but I want 18.69
extract number
rim_weight = (23* 36 *70);
rim_weight = rim_weight/3100; // retuns 18.69677419354839
rim_weight = rim_weight.toFixed(2); // returns 18.70
If you just want to truncate the number to two decimal places, first divide by 31, convert to an integral value using Math.floor
and then divide by 100:
rim_weight = (23 * 36 * 70); rim_weight = Math.floor(rim_weight / 31); rim_weight = rim_weight / 100; console.log(rim_weight);
just convert it to string then match the number up to the second place
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.