How to Convert string to float type in Golang?
ParseFloat function is an in-build function in the strconv library which converts the string type into a floating-point number with the precision specified by bit size.
Example: In this example the same string -2.514 is being converted into float data type and then their sum is being printed. Once it is converted to 8 bit-size and other times it is 32 bit-size. Both yield different results because ParseFloat accepts decimal and hexadecimal floating-point number syntax. If a1 or a2 is well-formed and near a valid floating-point number, ParseFloat returns the nearest floating-point number rounded using IEEE754 unbiased rounding which is parsing a hexadecimal floating-point value only rounds when there are more bits in the hexadecimal representation than will fit in the mantissa.
-2.514 -2.5139999389648438 -5.027999938964843
Please Login to comment...