Very recently I have faced a strange problem with JavaScript parseInt() function. It returns incorrect result when try to parse value like "08","09"...... But it works for "01" to "07".
So I have tried to find solution in community. Then find that this was a JavaScript bug.
Problem:
There is a "bug" with the parseInt JavaScript function. The bug is not something that will affect you very often, but it is something you should be aware of. We've seen the bug in every browser except Opera.
I've created a button to demonstrate the bug. The bug is that parseInt can return an incorrect value. For example, parseInt("08") results in 0 instead of 8. And parseInt("09") results in 0 instead of 9. The reason for this is because the zero in front is trying to tell the browser that this is an octal (base 8) number, and "08" and "09" are not valid octal numbers. The button below builds statements from parseInt("01") through parseInt("09") and shows what the resulting value is. But it also does parseFloat("01") through parseFloat("09"). This shows that the bug does not exist with parseFloat.
Solution:
parseInt(parseFloat(09))
Or,
parseInt(09, 10)
The "10" in the second example tells the browser that base-10 values should be used.
Hope that it will helpful for other developers.Thanks.
Sharing real-world experiences about C#, Dynamics CRM, Dynamics 365, Dynamics NAV/Business Central, SharePoint,PowerBI,ASP.net and more...
Subscribe to:
Post Comments (Atom)
Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'
Exception: Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'...
-
I have discussed about conversion of DataTable to Generic List<t>. We can do it in various way. I want to share with you some of them....
-
Basically, a thin client is a web based application and most of the processing is done on the server side. A thick client is installed int...
-
Very recently I got a mail from a junior guy he faced a problem every time when he installed the SQL server database on his workstation. Bu...
No comments:
Post a Comment