Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get 1.450 = 1.5 in javascript? (round to 1 decimal place) [duplicate]

Tags:

javascript

Possible Duplicate:
How do you round to 1 decimal place in Javascript?

My Value is 1.450 and I have to round it to 1 decimal place.

I want 1.450 = 1.5 in Javascript can any body fix this please.

like image 648
BASEER HAIDER JAFRI Avatar asked Nov 28 '25 06:11

BASEER HAIDER JAFRI


2 Answers

You need this:

var mynum = 1.450,
  rounded = Math.round(mynum * 10) / 10;
like image 193
BenM Avatar answered Nov 30 '25 21:11

BenM


suppose you have

var original=28.453;

Then

var result=Math.round(original*10)/10  //returns 28.5

From http://www.javascriptkit.com/javatutors/round.shtml

You can also see How do you round to 1 decimal place in Javascript?

like image 39
MaVRoSCy Avatar answered Nov 30 '25 20:11

MaVRoSCy