Swift : Convert (cast) String to Float




Problem :

You have a string value and you need to convert the string into type float.

Solution :

Use NSString for direct casting from type string to float. For example :

 var StrToFloat = (SomeInputString.text as NSString).floatValue

  See also : Swift : Convert (cast) String to Integer





By Adam Ng

IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.


Advertisement