How to prevent TextField to automatically convert a string like "678192091" to 6.78192091e+8


#1

Hello,

I am NS new-bee. I am try to use TextField to scan bar codes.

But whenever a string looks like number, the TextField automatically convert it to scientific-notation number for example:

I expect “678192091”, but in TextField I get “6.78192091e+8”.

Could you help to prevent TextField from doing that?

Thanks a lot,

Son Lam.


#2

EDIT: Not static but normal methods:

https://www.w3schools.com/jsref/jsref_toprecision.asp


#3

Hi,

I simple don’t want to convert to number. I would like to get it as a string.

Thanks,


#4

I think that’s what Number’s .toXXX() methods do: convert to string


#5

This works in HTML:

<!DOCTYPE html>
<html>
<body>

<p>Click the button to display the formatted number.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    var num = 678192091;
    document.getElementById("demo").innerHTML = num.toFixed(0);
}
</script>

</body>
</html>

#6

Have a look here:

https://jsfiddle.net/x4zv9v5g/1/


#7

Thanks so much for help.

I wonder if has any attributes to declare that the input it for string and do no convert to number in any format.

Although the value is a string, and it is looks like a number, just converts the string to number, which is very inconvenience.

Best Regards,


#8

I don’t really get what you mean… The content of the TextField in TypeScript will of course be a string, but in JavaScript, things are loosely typed, so if the JavaScript runtime thinks it looks like a number, it will probably store it internally as a number type.

How does the barcode get into the TextField in the first place? Can you share some of your code so I can see what exactly is going on?