Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to round a decimal place to the nearest whole in javascript?

I have a number with decimal places and I am wondering if it's possible to round the decimal to the nearest whole using javascript?

My number is: 4.59

I need my number to round to: 4.60

like image 217
Dennis Martinez Avatar asked Dec 22 '22 10:12

Dennis Martinez


1 Answers

Use Number.toFixed(number of decimal places):

var num = 4.59;
var rounded = num.toFixed(1);
like image 148
Daff Avatar answered Dec 24 '22 01:12

Daff