سؤال

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