Handling Scientific Notation in Make.com: A Step-by-Step Guide
Have you ever encountered a problem where you receive a scientific number and need to have it as a long string or number? For instance, you receive 1.0442665000000301e+21 and you want it to be 1044266500000030100000. This is a common issue that many Make.com users face and in this blog post, we will provide a step-by-step solution to this problem.
Understanding the Problem
Usually, one would use the formatNumber function to display numbers as a string (text). But when the number is a scientific notation, this throws an error. These sort of numbers being displayed as scientific notation usually means the number is too large to be stored as-is in the programming language. For example, in JavaScript (which Make uses), the max safe integer is 9007199254740991 (about 16 digits long). Similar auto-conversions happen in Excel when the number is too large.
The Solution
To solve this, you need to convert into a string, split up the scientific notation into the float and exponent parts, solve the value separately, and display them as a combined set. Here are the steps:
Step 1
Use the set multiple variables module to convert into string, and store the different parts of the number separately. Variable padding_required is basically exponent - decimal_places. Variable padding just contains a large number of zeros, to be trimmed to the number of padding zeros after the number.
Step 2
Remove the period from the first part, and trim the padding to the required length. For demonstration purposes, I show you how to set each part separately. You can do both at the same time and combine into a single output variable (e.g.: number_as_string).
Step 2B
Here’s how the setup looks like if you want to combine both variables in a later step.
Troubleshooting Tips
If you are not getting the correct values from your HTTP request, the loss of precision, is really how the value was stored in the first place. You’ll need to switch it to a string (text) format at point of entry, not when it is sent to Make. When a number is stored in scientific notation, you are already truncating the remaining decimal points. If you need the full “string” value, you need to store it (and send it over) as a string.
Conclusion
In conclusion, dealing with scientific notation in Make.com can be tricky but with the right steps, it can be managed effectively. Remember to convert the scientific notation into a string, split it up into the float and exponent parts, solve the value separately, and display them as a combined set. Happy Making!
You do have further questions?
Ask your question via E-Mail: Richard@make-app.de
Book a paid Support & Consulting Session
New Make.com user? Sign up through this Affiliate Link to receive 10.000 operations for FREE.