0

I have searched through a lot of threads and all of them give the same answer.

I am trying to add 0s right after the decimal point to an integer. If I have var a = 25. I want to modify a such that its value is 25.0. Most of the offered solutions either suggest appending a string ".0" or using .toFixed() which appends any number of 0s you want but still returns a string. I want the response to be float number and not a string.

Any thoughts on how I could achieve this?

Thanks.

12
  • 1
    possible duplicate of javascript convert int to float Commented Jan 14, 2014 at 21:59
  • 9
    Float numbers don't store data like that (or any number type for that matter). Such visual things must be done with a string. Commented Jan 14, 2014 at 21:59
  • 3
    You can't achieve this, that is why all the answer you've found uses a string. Commented Jan 14, 2014 at 21:59
  • That has to be done as a string. The number is 25, wether it's a float, int, decimal, whatever. To include trailing 0s it must be a string (which you do for display, not for storing it in your object). Commented Jan 14, 2014 at 22:00
  • 1
    Javascript doesn't have int and float. It has only number. Commented Jan 14, 2014 at 22:00

1 Answer 1

1

It has been a while since someone used this thread, but just in case someone needs it I think the answer you are looking for is:

.toFixed(2)

Example:

let number = 4;
return number.toFixed(2) //4.00
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.