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?

有帮助吗?

解决方案

.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());

其他提示

You have the ) in the wrong place

textelement = document.createTextNode(array[index].toExponential(3).toLocaleUpperCase());
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top