I know that you can convert a float into a string using
NSString *myString = [NSString stringWithFormat:@"%f", myFloat];
My question is what OTHER methods exist in Objective-C that can do that same?
thanks.
gcvt() | Convert float value to string in C This function is used to convert a floating point number to string. Syntax : gcvt (float value, int ndigits, char * buf); float value : It is the float or double value. int ndigits : It is number of digits.
The Float. toString() method can also be used to convert the float value to a String. The toString() is the static method of the Float class.
We can convert a string to float in Python using the float() function. This is a built-in function used to convert an object to a floating point number.
We can convert float and double to string using the C++11 std::to_string() function. For the older C++ compilers, we can use std::stringstream objects.
You could use NSNumber
NSString *myString = [[NSNumber numberWithFloat:myFloat] stringValue];
But there's no problem doing it the way you are, in fact the way you have in your question is better.
in a simple way
NSString *floatString = @(myFloat).stringValue;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With