I am trying to create a RoundUp function with help of Math.ceil
it working fine with positive number but do not round up the negative numbers
Here is what i am trying
var value = -12.369754; --> output = -12
// make value = 12.369754; and out put will be 13
var decimalPoints = 0;
if (decimalPoints == 0) {
value = Math.ceil(parseFloat(value));
}
console.log(value);
Here is the Fiddle http://jsfiddle.net/n7ecyr7h/
Why This function?
I need to create a function in which user will give a number and decimal points upto which he wants to round the number The RoundUp function will roundUp the given value to a given number of decimal points
For example if user enters 12.12445
and wants to roundUp to 3 decimal points
the output will be 12.125
Here is a table of required outputs with 2 decimal points
**Input** **output**
1.2369 1.24
1.2869 1.29
-1.1234 -1.13
-1.17321 -1.18
And here is the Updated Fiddle with original JS code http://jsfiddle.net/n7ecyr7h/1/
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…