0

Using the following library: http://jsfromhell.com/classes/bignumber

my big integer is not being rounded.

My code is the following:

x=1234.56;
y = new BigNumber(x);
document.write("<br>1 "+Math.round(x)  +"<br>");
document.write("<br>2 "+y.round()+"<br>"); // '1235'
document.write("<br>3 "+y.round(1)+"<br>"); // '1235.6'
document.write("<br>4 "+y.round(2)+"<br>"); // '1235.56'
document.write("<br>5 "+y.round(10)+"<br>"); // '1235.56'
document.write("<br>6 "+y.round(0, 1)+"<br>"); // '1234'
document.write("<br>7 "+y.round(0, 6)+"<br>"); // '1235'
document.write("<br>8 "+y.round(1, 1)+"<br>"); // '1234.5'
document.write("<br>9 "+y.round(1, BigNumber.ROUND_HALF_EVEN)+"<br>"); // '1234.6'

I am receiving the following output:

1 1235

2 1234.56

3 1234.56

4 1234.56

5 1234.56

6 1234.56

7 1234.56

8 1234.56

9 1234.56

JORd
  • 109
  • 1
  • 10

1 Answers1

0

The library you're using ask for precision and round type when you create your BigNumber, the round() method didn't take any parameter.

So you should change your code where:

y = new BigNumber(x);

To

y = new BigNumber(x, 0, 1);
Mario Santini
  • 2,905
  • 2
  • 20
  • 27