Search HoldMyTwist

Browse all posts

Convert decimal-comma text to a number in Make

Read decimal-comma correctly for Make Free. 19,95 -> 19.95, check the math, and see when you get a change in value from a separator error.

A balance comparing two arrangements of small beads

If you are using a decimal point as a comma in numbers, you may have problems. For example, parseNumber in Make will turn a text into a number if you pass the right decimal point.

That's why this free-plan exercise makes sure that your number from text gets converted correctly before you use it in your workflow.

Before you start

First you'll need an account on Make. You can create a Make Free account (opens in a new tab) or log in.

Set your scenario to Inactive and select Run once

You don't need any other app.

1. Create the decimal-comma input

  1. go to Scenarios
  2. click Create scenario
  3. in the top left, give it a name Decimal number practice
  4. Add Tools > Set variable
  5. Variable name raw_price
  6. Variable value 19,95
  7. Save this module
  8. Save this scenario
  9. Click Run once
  10. Check the result bubble for raw_price: 19,95

Full Make editor with raw_price set to the fictional decimal-comma text 19,95

Full Make editor with raw_price set to the fictional decimal-comma text 19,95
Open full-size image

2. Parse using a comma as the decimal separator

  1. Hide results panel
  2. Add new Tools > Set variable by clicking plus sign to the right of Tools
  3. Variable name = price_number
  4. Paste below expression to Variable value. Ensure raw_price is coloured token (module 1). Change source token in case of different module number.
  5. Save module / scenario
Text to copy

{{parseNumber(1.raw_price; ",")}}

The comma argument of parseNumber tells it what character to use as the decimal separator.

Full Make editor applying parseNumber to raw_price with a comma separator

Full Make editor applying parseNumber to raw_price with a comma separator

The comma argument of parseNumber tells it what character to use as the decimal separator.

Open full-size image

Watch out

Just because you successfully run does not mean you got it right. When using a dot as the separator, you get 1995 out of 19,95 with this technique. Make sure to use the source decimal separator. Compare a small example you know against it and then you can go for a larger input.

3. Check the converted value

  1. click run once
  2. open the result bubble of the second Tools module
  3. in the Output section look for price_number: 19.95

Full Make editor showing price_number output 19.95 after parsing 19,95

Full Make editor showing price_number output 19.95 after parsing 19,95
Open full-size image

For the arithemtic test, you need to replace your current expression with the given expression below for a moment. Save the module and re-run. Make sure you get 21.95.

Once you are done with this test, make sure you replace your old expression with your original expression to continue with the exercise.

Text to copy

{{parseNumber(1.raw_price; ",") + 2}}

If the value is much larger than expected

First check if decimal separator matches. Don't just strip all commas without knowing if they're for fractions or thousands groups. In this case the text is expected to be just digits with one decimal comma. Other characters like currency signs, blanks or mixed formats would require additional checks before trusting the value you get.

Parse numbers with thousands separators

Use the source's decimal. If it's fictional text like 1,234.56, the comma is used to delimit thousands and the period is used as the decimal.

  1. In the first "Tools - Set variable" module, change the "Variable value" to "1,234.56". (but keep the name 'raw_price'). Then save the module.
  2. In the 2nd module use price_number and paste the following expression in Variable value. Make sure that raw_price is the coloured token of module 1 and save. 2nd module price_number
  3. Save the scenario, and do "Run once". Then go to the result bubble of the second module. In Output, look for price_number: 1234.56.
Text to copy

{{parseNumber(1.raw_price; ".")}}

For dot group of text in which decimal comma is used, set raw_price as 1.234,56 and use this comma expression. Then Save and run. The expected number is still 1234.56.

Text to copy

{{parseNumber(1.raw_price; ",")}}

When you use comma expression against 1,234.56 you get 1.23456. (It does execute).

To make sure it is an arithmetic issue, change back the raw_price to 1,234.56

Use the dot expression. Add + 2 temporarily in expression before you put the }} in it.

Save both modules. Scenario.

Run again. You should get 1236.56

Change the parse only expression back.

1,234 Ambiguous. If you select comma, you get 1.234. If you select dot, you get 1234. Make sure you know what the source is aiming for. Take a look at columns with both types of numbers before they get converted. Check a known input against expected output.

Input text is 1,234.56 (with thousands comma and dot decimal separator).

Output: price_number: 1234.56

Full Make editor showing price_number: 1234.56 after parsing fictional comma-grouped text with a dot decimal separator.

Full Make editor showing price_number: 1234.56 after parsing fictional comma-grouped text with a dot decimal separator.
Open full-size image

If you want this as a step in a recurring workflow, use Make. If you just want to do this conversion in LibreOffice Calc, then there is a documented NUMBERVALUE function (opens in a new tab) that accepts =NUMBERVALUE("19,95"; ",") (yielding the number 19.95). The decimal separator that's shown will depend on the number format of the cell. If you want to do a bigger workflow, you can start with Make Free (opens in a new tab). Review the Free-plan limits before scheduling a big workflow.

Screenshots: imaginary practice data Calculation reference: Make math functions (opens in a new tab)

Share this post