I have a value like that:

20.93

I'd like to round it to

20.90

How can I do that in Javascript ?

Thanks!

Multiply the number by 10, round it and then divide the number by 10:

```
var result = Math.round(20.93 * 10) / 10
```

I think this should work:

*number*.toFixed(1);

```
var num= 20.93
num = Math.floor(num * 10) / 10; // 20.9
num = Math.ceil(num * 10) / 10; //21
```

I take it that you want the trailing zero. None of the answers give you that. It has to be a String to have the trailing zero.

```
function my_round(x){
return Number(x).toFixed(1) + '0';
}
```

If you don't care about the trailing zero and you want a Number (not String), then here's another way to round to decimal places in JavaScript. This rounds to decimal place d.

```
function my_round(x, d){
return Number( Number(x).toFixed(d) );
}
```

You would do

```
my_round('20.93', 1);
```

or

```
my_round(20.93, 1);
```

**You can set** `toFixed(1)`

. **but set value = 20.96** then **you have 21 and not 20.90**;

BUT with my function always will be 20.90 than 20.93 like 20.98/97/96/95...

```
<script>
var num = 20.93;
function vround(num) { // CREATE BY ROGERIO DE MORAES
var Dif = (num.toFixed(2)-num.toFixed(1)).toFixed(2);
Dif = Dif * 100;
if(Dif <= -1) {
var n = num.toFixed(2) - 0.05;
vround(n);
} else {
var n = num.toFixed(1)+0;
console.log(n);
}
}
vround(num);
</script>
```

*I create this function for get you value, but can change, if you wanna more forms.*

Similar Questions

I'm using this code to sum decimal values. SUM(Amount) as TotalAmount Amount column is decimal datatype Amount decimal (10,4) After summing up the columns I get values like this 13500.8765 12005.00

how can we convert a javascript string variable to decimal ? is there a function such as parseInt(document.getElementById(amtid4).innerHTML)

This question already has an answer here: Variable interpolation inside printf-style formatting functions 2 answers In Objective-C, how do you round a number to n decimal places, when n is a va

Is there a way to write a JavaFX app with just JavaScript files now that Nashorn is available in Java 8? Where can I find more info or videos on this? How would you compile it? Or is there a minimal s

How to round a decimal number to nearest 5 or nearest 10 in php

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.

How to retain two decimal points in flex using Math.Round code: txtTotal.text=Math.round((Number(txtRate.text)*Number(txtQuantity.text))).toString(); here the rate is a constant 1.1 and quantity is v

Possible Duplicate: Round a double to 2 significant figures after decimal point I know that there is plant of examples how to round this kind numbers. But could someone show me how to round double,

I currently have a function which will take an input and round it to 4 decimal places, it looks like this: public static double table_round(double n) { return (double) Math.round(n * 10000) / 10000;

What I'd like is a method to convert a double to a string which rounds using the half-up method. I.e. if the decimal to be rounded is a 5, it always rounds up the previous number. This is the standard

Does Angular have a built-in directive to round the input value? The number filter is not appropriate in this case because I want to round the actual val in ng-model as well. If I have to write one, w

I have a data set of stock prices that have already been rounded to 2 decimal places (1234.56). I am now trying to round to a specific value which is different for each stock. Here are some examples:

I need to round a decimal in a sql query on Oracle 10g to the nearest even number. If the number is even, it should be returned. If the number is odd, the next even number should be returned. This is

I have one cell formatted as Number and with 2 decimal places. The actual number is 69.30217 so in my cell, imagine cell A1, it appears like 69.30. This is OK. With that cell, I'm making some concaten

I'm using the following regexp to validate numbers in my javascript file: var valid = (val.match(/^\d+$/)); It works fine for whole numbers like 100, 200, etc, however for things like 1.44, 4.11, etc

Math.Round(4816.5) is returning 4817. I want to Round up only if decimal is >5 and not >=5 So here i need result as 4816. Pls give me solutions.

This should be easy, but I can’t find a built in method for it, the .net framework must have a method to do this! private decimal RoundDownTo2DecimalPlaces(decimal input) { if (input < 0) { throw n

This question already has an answer here: How to round a number to n decimal places in Java 16 answers While there are many rounding questions answered in StackO., I could not quite translate t

Possible Duplicate: How to round and format a decimal correctly? I have this: double xValue = 0.0; double yValue = 0.0; foreach (var line in someList) { xValue = Math.Round(Convert.ToDouble(xDisplac

If I have a bunch of queries that I am executing, wrapped in an Activerecord transaction, are all those queries sent to the database in 1 round trip (ie all queries sent to db, and response sent back)

does anyone know how to round corners of div using javascript, but round only lets say 1 or 2 corners which you can choose not all of them. Thank you

I have a text box where I can enter numeric data which I can have decimals up to two decimal places, example 125.02 or just 125. However, I want to round all data that is entered with a decimal up, ex

This question already has an answer here: JavaScript: formatting number with exactly two decimals 12 answers Working on a form where I am doing a minus from two forms and showing the result in

I am validating a decimal number using JavaScript. Am just using NaN var a = 12345.67 Is there any javascript function to get the count or the value itself before and after decimal point . before() sh

Just wondering how i could round my code to two decimal places rather than the 10 or so it gives? Thank you in advance. print financial return of outcome 1 =,$+str(out1)

I'm new to mysql and need some basic things. I need to round the decimals like : 21,4758 should be 21,48 0,2250 should be 0,22 23,0850 should be 23,08 22,9950 should be 22,99 I tried lots of thing b

I am trying to truncate a decimal value in Python. I don't want to round it, but instead just display the decimal values upto the specified accuracy. I tried the following: d = 0.989434 '{:.{prec}f}'.

Possible Duplicate: c# - How do I round a decimal value to 2 decimal places (for output on a page) i have value of 1.564 and 1.565 i need round this value to 1.56 and 1.56,which function suitable fo

Is there a way to encode regular javascript utf-8 string into decimal 0-9 ( or octal 0-7 if that's more convenient) (octal or base10) ? I saw this thread for php, I want similar for javascript. Encodi

I have the below JavaScript syntax: var discount = Math.round(100 - (price / listprice) * 100); This rounds up to the whole number, how can I return the result with two decimal places?

Suppose I have the following DataMapper model: class Payment include DataMapper::Resource property :id, Serial property :amount, Decimal, precision: 8, scale: 2 end Then I do the following: p = Payme

My Regular Expressions knowledge is next to none but I'm having to have some client-side valiation against a text box which only allows numbers up to two decimal places with no other input. This scrip

I have a DOUBLE data type column in my MySQL table and I have a value of: 14.5299 But PHP number_format rounds that value to: 14.5300 And if I just echo 14.5299, it outputs: 14.53 How can I output

Possible Duplicate: c# - How do I round a decimal value to 2 decimal places (for output on a page) I want to truncate the decimals like below i.e. 2.22939393 -> 2.229 2.22977777 -> 2.229

I want to round a float with many decimal places, such as 2.638232371 down to one decimal place, such as 2.6. I found this will do so: %.2f % 1.93213 #=> 1.93 But what is %.2f? and is the resu

I am facing problem while rounding the decimal value in C# using Math.Round(a, 2); When I'm rounding 1.275 by 2 decimal points, the result is 1.27. When I'm doing the same for 1.375, the result is 1.3

This question already has an answer here: How do you round to 1 decimal place in Javascript? 8 answers Hello I have the code for a mileage calculator and I want the displayed mileage to be roun

What can I use as a decimal type in JavaScript? It's not supported (0.1 + 0.2 !== 0.3), and I need it for representing exact values in a banking/financial application. See The State and Future of Java

How do I round an NSNumber to zero decimal spaces, in the following line it seems to keep the decimal spaces: NSNumber holidayNightCount = [NSNumber numberWithDouble:sHolidayDuration.value];

Possible Duplicate: How can I round a float value to 2 post decimal positions? Lets say I have a double number of 3.46. How do I round it to 3.50? I tried NSLog(@res: %.f, round(3.46)); but it r

This question already has an answer here: Most Pythonic way to print *at most* some number of decimal places [duplicate] 3 answers I am trying to round a floating point number in python to zero

I have scenario where if user enters for example 000.03, I want to show the user it as .03 instead of 000.03. How can I do this with Javascript?

I have a little problem with round() in php. I don't know, if I really make it correct. (it is an order system) $amount can be decimal 14,8 $price can be decimal 10,5 (in the database) I am using the

How do I round a double to 5 decimal places, without using DecimalFormat?

I need to round any non-integers up to the nearest integer, regardless of whether the number after the decimal place is >5 or not.

i'd like to make a javascript validation that will accept all numeric and decimal point format. For example : 1,000,000.00 is OK 1.000.000,00 is OK 1.000,000.00 is not OK 1.000,000,00 is not OK 1,000.

I just want to change the shape of view from Square to Round. As i try with cornerRadious, But it just round the corner only. As I want to make whole view as a round shape.

In C# rounding a number is easy: Math.Round(1.23456, 4); // returns 1.2346 However, I want to round a number such that the fractional part of the number rounds to the closest fractional part of a pre

How can I round a decimal number (floating point) to the nearest integer? e.g. 1.2 = 1 1.7 = 2

This question already has an answer here: How to round a number to n decimal places in Java 16 answers Round a double to 2 decimal places 14 answers I would like the result of this to retur