d4rty d4rty - 1 year ago 72
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 Source

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

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