How to multiply decimals out of variable of type Number in TypeScript?

Viewed 302

Lets say I have an number which is equal to 288.65 and I want to multiply out the decimal point to achieve the desired result of 28865

If I simply just try say console.log(288.65 * 100) it will return 28864.999999999996 I am not sure why it is doing this, any help will be much appreciated.

1 Answers

You can use Math.ceil and with Math.round

The Math.ceil() function always rounds a number up to the next largest integer.

The Math.round() function returns the value of a number rounded to the nearest integer.

const num = 288.65;

const result1 = Math.round(num * 100);
const result2 = Math.ceil(num * 100);

console.log(result1);
console.log(result2);

Related