0

I'm using following Javascript code in one of my calculations:

var bx1 = parseFloat(tx9) * ( 70 / 100 );

The output of bx1 is showing in decimals. However, I want it to be no decimals. Looking for some help!

Eg. bx1 = 700*70/100 = 489.999. I want it either 489 or 490, anything is fine.

Angelos Chalaris
  • 6,611
  • 8
  • 49
  • 75
user2723454
  • 61
  • 1
  • 1
  • 6

2 Answers2

1

Use Math.round().

var = Math.round(parseFloat(tx9) * ( 70 / 100 ));
stelioslogothetis
  • 9,371
  • 3
  • 28
  • 53
0

You can use either Math.round(), Math.floor() or Math.ceil():

var bx1 = 489.999;
console.log(Math.floor(bx1));
console.log(Math.round(bx1));
console.log(Math.ceil(bx1));
  • floor() will round down your number.
  • round() will round your number (based on decimal value).
  • ceil() will round up your number.
Angelos Chalaris
  • 6,611
  • 8
  • 49
  • 75