Tuesday, July 19, 2022

[FIXED] How do I parse a string to a float or int?

Issue

  • How can I convert a str to float?
    "545.2222"  →  545.2222
    
  • How can I convert a str to int?
    "31"        →  31
    

Solution

>>> a = "545.2222"
>>> float(a)
545.22220000000004
>>> int(float(a))
545


Answered By - Harley Holcombe
Answer Checked By - Gilberto Lyons (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.