For converting a string to float you can use float(). Eg.float('1.2123') You can not convert '*' into float because its an operator that's why error is coming.

#observe the code
volume = float(input("Enter volume of sphere in mm^3: "))

input() = Takes input from user and stores it in string

float() = It is used to convert strings to float

Your code is volume = float(input("Enter volume of sphere in mm^3: "))

1st input() takes input from user in string then float() converts it into float.

But a = 1.4*1.0e6 there is no input() function involved thats why it's a float.

You can simply achieve your work by

volume = eval(input("Enter volume of sphere in mm^3: "))

OR

volume = input("Enter volume of sphere in mm^3: ").split("*")
volume = float(volume[0])*float(volume[1])

split(separator)- It splits a string into an array of sub-strings, by a separator string provided by user

You can read about eval from here:- Read abut eval() from here

Answer from Abhay Kumar on Stack Overflow
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ how to convert string to float in python?
Convert String to Float in Python - Scaler Topics
May 5, 2022 - For converting the list of strings ... have to iterate the string list and take the values one by one and then convert the string values to the floating values and then append all the float values to the floating value list...
๐ŸŒ
Cherry Servers
cherryservers.com โ€บ home โ€บ blog โ€บ python โ€บ how to convert string to float in python (6 different ways)
How to Convert String to Float in Python (6 Different Ways) | Cherry Servers
July 25, 2024 - ... Using the float() function is the most common way to convert string to float in Python. Whatโ€™s more, it is a built-in function which means it comes with standard Python installation.
Discussions

Python string to float conversion
I don't know what you mean: >>> a = '1721244344.700249000' >>> float(a) 1721244344.700249 These are all the decimal places. Trailing zeros will always be omitted as they are irrelevant. If you want to show them, do so when you output the value: >>> print(a.format("{:.9}")) 1721244344.700249000 More on reddit.com
๐ŸŒ r/learnpython
18
5
July 29, 2024
python - How do I parse a string to a float or int? - Stack Overflow
How can I convert an str to a float? "545.2222" -> 545.2222 Or an str to a int? "31" -> 31 For the reverse, see Convert integer to string in Python and Converting a float... More on stackoverflow.com
๐ŸŒ stackoverflow.com
convert string to float?
if you really want to convert "1" of type str to 1 of type int then you can do something like that: ord("1")-48 this returns Unicode value of the digit, which is 48 for "0", 49 for "1", 50 for "2" etc. from that, it should be easy to create a floating point number in the for loop More on reddit.com
๐ŸŒ r/learnpython
16
2
September 22, 2022
How to convert string to float ?
a='25$' b=float(''.join([i for i in a if i.isdigit()])) print(b) Use list iteration to take the digits and join the elements in the new list and convert to float value. More on reddit.com
๐ŸŒ r/learnpython
42
69
November 14, 2022
๐ŸŒ
Hostman
hostman.com โ€บ tutorials โ€บ how to convert string to float in python
How to Convert String to Float in Python
March 31, 2025 - In this article weโ€™ve covered a common example of type casting which is converting a string to a float using the float() function. We also used the try/except block to handle conversion errors when the input string format is not valid.
Price ย  $
Call ย  +1 844 286 2130
Address ย  1999 Harrison St 1800 9079, 94612, Oakland
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ python string to float conversion
r/learnpython on Reddit: Python string to float conversion
July 29, 2024 -

Hi all, I have a string a = '1721244344.700249000', I want to convert it to a floating value.

Float() is returning only 2 places after decimal point. Like 1721244344.7

Is there a way I can convert the entire string to a floating point value and get all the decimal (upto 9 places after decimal point)?

I have to use python v2.7 for this.

Edit: I do not have problem in printing the all 9 decimal places but I need the floating value so that I can subtract another value so that I get the difference with accuracy upto 9 th decimal point.

๐ŸŒ
Python Engineer
python-engineer.com โ€บ posts โ€บ string-to-float
How to convert a string to float/integer and vice versa in Python - Python Engineer
February 9, 2022 - The result will include the whole number part of the float, as the decimal part is discarded during float to int conversion. ... ```python number_as_string = "3.14159" number_as_float = float(number_as_string) number_as_integer = int(number_as_float) print(number_as_integer) ... A ValueError is also thrown in any other case where the string cannot be converted to a number.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-string-to-float-in-python
Convert String to Float in Python - GeeksforGeeks
July 15, 2025 - It converts a string into a Decimal object, effectively avoiding common floating-point rounding errors. ... eval() function reads and runs a string as a Python expression. It can turn a numeric string like "33.28" into a float. However, it's risky to use with untrusted input because it can run harmful code.
Find elsewhere
๐ŸŒ
Centron
centron.de โ€บ startseite โ€บ how to convert a string to a float in python
How to Convert a String to a Float in Python
February 7, 2025 - This tutorial was tested with Python 3.9.6. 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.
๐ŸŒ
ServiceNow
servicenow.com โ€บ docs โ€บ r โ€บ washingtondc โ€บ api-reference โ€บ server-api-reference โ€บ DynamicTranslation.html
Docs | ServiceNow
Loading application ยท Your web browser must have JavaScript enabled in order for this application to display correctly
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Convert a String to a Number (int, float) in Python | note.nkmk.me
April 29, 2025 - In Python, you can convert a string (str) to a number using int() for an integer or float() for a floating-point number. Convert a string to int: int() Convert a string to float: float() Convert a bin ...
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ stdtypes.html
Built-in Types โ€” Python 3.14.3 documentation
2 weeks ago - For example, the hexadecimal string 0x3.a7p10 represents the floating-point number (3 + 10./16 + 7./16**2) * 2.0**10, or 3740.0: ... Applying the reverse conversion to 3740.0 gives a different hexadecimal string representing the same number: ... The complex type implements the numbers.Complex abstract base class. complex also has the following additional methods. ... Class method to convert a number to a complex number.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_casting.asp
Python Casting
Python is an object-orientated language, and as such it uses classes to define data types, including its primitive types. Casting in python is therefore done using constructor functions: int() - constructs an integer number from an integer literal, a float literal (by removing all decimals), or a string literal (providing the string represents a whole number)
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ json.html
json โ€” JSON encoder and decoder
3 weeks ago - If None (the default), it is equivalent to int(num_str). This can be used to parse JSON integers into custom datatypes, for example float. parse_constant (callable | None) โ€“ If set, a function that is called with one of the following strings: '-Infinity', 'Infinity', or 'NaN'.
๐ŸŒ
Godot Engine
docs.godotengine.org โ€บ en โ€บ stable โ€บ tutorials โ€บ scripting โ€บ gdscript โ€บ gdscript_basics.html
GDScript reference โ€” Godot Engine (stable) documentation in English
GDScript is a high-level, object-oriented, imperative, and gradually typed programming language built for Godot. It uses an indentation-based syntax similar to languages like Python. Its goal is to...
Top answer
1 of 16
3117
>>> a = "545.2222"
>>> float(a)
545.22220000000004
>>> int(float(a))
545
2 of 16
605

Python2 method to check if a string is a float:

def is_float(value):
  if value is None:
      return False
  try:
      float(value)
      return True
  except:
      return False

For the Python3 version of is_float see: Checking if a string can be converted to float in Python

A longer and more accurate name for this function could be: is_convertible_to_float(value)

What is, and is not a float in Python may surprise you:

The below unit tests were done using python2. Check it that Python3 has different behavior for what strings are convertable to float. One confounding difference is that any number of interior underscores are now allowed: (float("1_3.4") == float(13.4)) is True

val                   is_float(val) Note
--------------------  ----------   --------------------------------
""                    False        Blank string
"127"                 True         Passed string
True                  True         Pure sweet Truth
"True"                False        Vile contemptible lie
False                 True         So false it becomes true
"123.456"             True         Decimal
"      -127    "      True         Spaces trimmed
"\t\n12\r\n"          True         whitespace ignored
"NaN"                 True         Not a number
"NaNanananaBATMAN"    False        I am Batman
"-iNF"                True         Negative infinity
"123.E4"              True         Exponential notation
".1"                  True         mantissa only
"1_2_3.4"             False        Underscores not allowed
"12 34"               False        Spaces not allowed on interior
"1,234"               False        Commas gtfo
u'\x30'               True         Unicode is fine.
"NULL"                False        Null is not special
0x3fade               True         Hexadecimal
"6e7777777777777"     True         Shrunk to infinity
"1.797693e+308"       True         This is max value
"infinity"            True         Same as inf
"infinityandBEYOND"   False        Extra characters wreck it
"12.34.56"            False        Only one dot allowed
u'ๅ››'                 False        Japanese '4' is not a float.
"#56"                 False        Pound sign
"56%"                 False        Percent of what?
"0E0"                 True         Exponential, move dot 0 places
0**0                  True         0___0  Exponentiation
"-5e-5"               True         Raise to a negative number
"+1e1"                True         Plus is OK with exponent
"+1e1^5"              False        Fancy exponent not interpreted
"+1e1.3"              False        No decimals in exponent
"-+1"                 False        Make up your mind
"(1)"                 False        Parenthesis is bad

You think you know what numbers are? You are not so good as you think! Not big surprise.

Don't use this code on life-critical software!

Catching broad exceptions this way, killing canaries and gobbling the exception creates a tiny chance that a valid float as string will return false. The float(...) line of code can failed for any of a thousand reasons that have nothing to do with the contents of the string. But if you're writing life-critical software in a duck-typing prototype language like Python, then you've got much larger problems.

๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-convert-string-to-float
How to Convert String to Float in Python: Complete Guide with Examples | DigitalOcean
July 10, 2025 - Learn how to convert strings to floats in Python using float(). Includes syntax, examples, error handling tips, and real-world use cases for data parsing.