d4rty d4rty - 2 months ago 7
Javascript Question

Create a float from two int numbers in JavaScript

How can I construct a float value from two whole values?

var amountBeforeComma = 5;
var amountAfterComma = 234;

var amount = ?? //amount == 5.234

Answer

Since no one mentioned... There's the JavaScript way:

var num = +(amountBeforeComma + "." + amountAfterComma);