I am writing a very simple html calculator. The end result and user inputs are displayed in the "textDisplay_" area below:
<div id ="textDisplayRow_"> <div id = "textDisplay_" class = "calcTextDisplay">0.0</div> </div>
I also have JavaScript code that receives and parses the displayed value in a float using the following functions:
function getCurrentText() { "use strict"; return document.getElementById("textDisplay_").innerHTML; } function getDisplayedNum() { "use strict"; if (getCurrentText() === emptyMesg) { return maxSafeInt; } var t = 1*getCurrentText();
This code works great on desktop browsers (I tested it on Chrome, FireFox, and IE). They all look good and say if I enter: 3.14 * 2 and press '=', they give me 6.28.
However, on my Android phone 4, using the latest versions of mobile chrome and firefox, all decimal numbers are rounded up! so if I hit "3.14 * 2 =", I get "6"!
How can I fix this problem? I looked at other posts containing parseFloat not working, and none of them look like this problem. Also, both give similar results:
1*getCurrentText(); parseFloat(getCurrentText(), 10);
One option is to write your own parseFloat (I previously did this for the microcontroller!), But I really don't want to go that route.
Thank you very much in advance.
javascript mobile-chrome
AleX_ Apr 05 '16 at 23:02 2016-04-05 23:02
source share