質問

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