When exporting CSV from Excel, numeric fields are often converted to scientific notation — e.g., 0.000089 becomes 8.90E-05. Inserting into MySQL works fine, but using bcmul throws bcmul(): bcmath function argument is not well-formed.
Convert Back with sprintf
The most straightforward approach is using sprintf to convert scientific notation back to a float:
| |
But it breaks when the decimal places exceed 6:
| |
%f defaults to 6 decimal places, and anything beyond that gets truncated.
Dynamically Calculate Decimal Places
Extract the exponent from E- and dynamically adjust the sprintf precision:
| |
This correctly converts the number regardless of how many decimal places it has.
