Question

I'm showing a result witht this expression:

textelement = document.createTextNode(array[index].toExponential(3));

and it shows, for instance:

5.636e+9

Is there any way to show this result with an uppercase E, picking up this result: 5.636E+9?

In other words: How turn this 'e' into an 'E'?

I've tried this:

.toExponential(3)).toLocaleUpperCase();

but fails.

Any idea?

Was it helpful?

Solution

.toExponential(3)).toLocaleUpperCase(); won't work because you are calling toLocaleUpperCase() on the result of this statement:

document.createTextNode(array[index].toExponential(3));

which doesn't return a string, instead you need to call toLocaleUpperCase() or toUpperCase() on the result of the toExponential() method itself, so that the resulting string is modified before it is inserted into HTML tree.

You can do it like this:

textelement = document.createTextNode(array[index].toExponential(3).toUpperCase());

OTHER TIPS

You have the ) in the wrong place

textelement = document.createTextNode(array[index].toExponential(3).toLocaleUpperCase());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top