cancel
Showing results for 
Search instead for 
Did you mean: 

conversation AI - number with 2 decimal places with a comma as a separator.

alicja_z
Explorer
0 Kudos

Hello,

when using conversation AI I want to convert a number value to a number with 2 decimal places with a comma as a separator.

e.g.

"money": [

{

"confidence": 0.99,

"raw": "18.90 €",

"amount": 18.9,

"currency": "EUR",

"dollars": 22.869

}

money.amount should be converted to18,90.

My target:

money.amount 20 --> memory field 20,00

money.amount 20,9 --> memory field 20,90

money.amount 20,99 --> memory field 20,99

How can I achieve this?

Best regards

Alicja

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

You just want a script that will take a number -- either in the form of 20 or 20.9 or 20.90 -- and the result will be with comma and 2 decimal places?

View Entire Topic
JonasB
Contributor

Hi Alicja,

there is a dedicated "formatNumber" helper in the scripting syntax for this purpose, see https://help.sap.com/docs/conversational-ai/concepts-of-sap-conversational-ai/scripting-syntax#worki...

e.g. for edit memory

"{{formatNumber nlp.entities.money.[0].amount, 2, ",", "."}}"

for formatting the number detected via money entity in the German number format 9.999,00.

Regards
Jonas

alicja_z
Explorer
0 Kudos

Hi Jonas,

thanks for your answer. I try to save the converted value in memory field. I have following input for entity money:

I tried different options to get the correct format:

1. {{formatNumber memory.money.amount 2 ","}}

2. {{formatNumber memory.money.amount, 2, ","}}

3. {{formatNumber nlp.entities.money.[0], 2, ",", "."}}

I get following warnings / erros:

What I'm doing wrong?

Best regards

Alicja

alicja_z
Explorer
0 Kudos

Hi Jonas,

Now I'm able to use this formatting option in text message 🙂 Thank you!

But it's not working for memory input.

Best regards

Alicja

JonasB
Contributor
0 Kudos

Hi,

for edit memory action you need to put the handlebars expression into double quotes, as the result needs to be valid JSON.

I missed the „.amount“ in my example above indeed - corrected that.

Regards

alicja_z
Explorer
0 Kudos

Hi Jonas,

it works now 🙂 thank you!

Best regards

Alicja

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

ali_zip consider marking the answer as accepted