1

I need to convert a number with a value of 1.10 to a lossless floating point value. How can I achieve this in JavaScript.

1.10 when outputting and assigning the last 0 is lost, the result is 1.1, how to make sure that 0 is not lost when assigning in JavaScript

2 Answers2

3

From a number point of view, 1.10 and 1.1 are the same. The way to make this zero not to get lost is by working with strings instead of numbers, but then you lose many functionalities, like calculations.

Marcos Sandrini
  • 400
  • 2
  • 10
2

it can be done using toFixed() in javascript. for you number it can be done like this:

 console.log(1.10.toFixed(2))
Anonymous Coder
  • 556
  • 2
  • 16