Scientific notation

Hello,

I receive a scientific number and would need to have it as long string or number as just the numbers.

I receive:

1.0442665000000301e+21

I want:

1044266500000030100000

How can I do this?

1 Like

This is an excellent question!

Error when formatting scientific numbers

Usually one would use the formatNumber function to display numbers as a string (text)

Screenshot_2023-09-04_160934

But when the number is a scientific notation, this throws an error

Screenshot_2023-09-04_160900

Failed to map ‘value’: Function ‘formatNumber’ finished with error! ‘1.0442665000000301e+21’ is not a valid number or using unsuitable separator.


Why there is such 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.

Screenshot_2023-09-04_160948


Possible way to display the full number (as a string)

To solve this, you need to convert into a string, split up the scientfic notation into the float and exponent parts, solve the value separately, and display them as a combined set.

Step 1

I used 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.

Output:

Step 2

I 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)

Output:

Screenshot_2023-09-04_160926

Step 2b

Here’s how the setup looks like if you want to combine both variables in a later step

Screenshot_2023-09-04_160925


Single Module?

It is possible to combine these two steps into a single module, but some “tricks” are required to do so plus it makes it difficult to maintain. If you really need this I am available for a consult.

2 Likes

Thats a great solution, thank you! :slight_smile:

The only issues is that I am not getting teh crrect values from my http request.

I get:

1.0442665000000402e+21

It really is:

1044266500000040285630

The mathamatic solution and tools you showed will lead to:

1044266500000040200000

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 entry1, not when it is sent to Make. Like I said previously, there are maximums and limitations on how large numbers are being stored, so applications and programs will convert them automatically if not stored as a string.

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 string2.


References:

1 Why does Excel treat long numeric strings as scientific notation even after changing cell format to text - Super User

2 serialization - Why would you use a string in JSON to represent a decimal number - Stack Overflow

2 Likes

Hello smaliew,

I am requesting a shipment Label from Post (Austria) and the tracking code is what I would need.

I use a https request with soap envelope settings to get the data. The Post provider says it is send as string, but make only give me the truncated int value.

Can i turn settings at the http request module to get the value as string?

message

I think I found the issue!

Setting the “Parse response” in the http request module leads to the truncation of the number!!!

image

Why is make doing this? :face_with_raised_eyebrow:

2 Likes

Here is the solution:

Make an “Parse XML” Module and select this checkbox.

4 Likes