I have a webview with javascript-interface.
From within this webview i do certain javascript operations.
In one of those i set an onclick attribute for one of the elements in my webcontent. ( using jquery)
button.attr("onclick", "Android.doStuff(".concat(stringContainingOnlyNumbers).concat(")"));
As you might guess the variable stringContainingOnlyNumbers holds a String containing only numbers.
Android is the keyword for my javascript-interface.
If i click the button i manipulated the method doStuff is gettin called on the interface.
Everything fine so far.
But what the String Parameter holding looks like a float value.
So what looks like this on js side:
1344810353
Comes out on my interface like this:
1.34447e+09
Can anyone help me out here and explain why this conversion happens?
That isn’t really a conversion, it’s just rewriting it to fewer decimal digits using scientific notation.
1344810353 rounded to 6 digits is 1.34447e+09, which btw is 1.34447 * 10^9.
It’s a float, and javascript tends to shorten numbers when concatenating them as strings.
Here’s an example: http://jsfiddle.net/YGC8B/
You can fix this by iterating through the numbers digits and displaying them one by one.
Here’s a working example: http://jsfiddle.net/Tj5Zy/
A side note:
It’s best not to use the onclick attribute of an element, it’s slightly deprecated. I would recommend attaching the event.
And since you’re using jQuery, it’s just all the easier.