Tim Moores wrote:If you want to use getElementById("USD") you need to have an element that has an id of "USD". AFAICT, there is none with that id.
Campbell Ritchie wrote:I don't know much JS, but try the following two versions. I think the first version is better because there is no repetition of the number literal 0.00001017.Similarly, separate the removal of commas (line 153) from the assignment to num11.
Stephan van Hulst wrote:
Hendrik Bezuidenhout wrote:
Campbell Ritchie wrote:Why have you got the = assignment operator twice in the same line?
The second = is for the value to be used for part of miltiply
Campbell was really asking a rhetorical question. He means that using multiple assignments in a single statement is poor programming. Instead, split the expression in two separate statements.
Stephan van Hulst wrote:Welcome to CodeRanch!
The toLocaleString() function takes an optional 'options' parameter which has a 'maximumFractionDigits' property that defaults to 3.
The operands to your 'test2BTC' multiplication are too small, the answer is rounded to "0.000" which is displayed as "0".
The same problem occurs with your first two multiplications: Notice that the results never have more than 3 fractional digits.
To solve your issue, specify the maximum number of fractional digits you want to display, in the range 0 to 20: