Created
April 29, 2020 11:02
-
-
Save juanbenitez/7d41ce71be4efc8ea921bbd146eab955 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//input & output variables definition | |
let input_var = event.conversation.variables.YOUR_VARIABLE_HERE; //your input variable name | |
let output_var = "YOUR_VARIABLE_HERE"; //your output variable name | |
// Decimals to show | |
// 2 --> currency format | |
// 1 --> percentage format | |
const decimals_to_show = 2; //change this value | |
//--------------------------------------------------- | |
//--------------------------------------------------- | |
function show_decimals(input_number, decimals){ | |
let formated_number = new Intl.NumberFormat('en-US',{useGrouping: false, | |
maximumFractionDigits: decimals}).format(input_number); | |
return formated_number; | |
} | |
let mapping = {}; | |
mapping[output_var] = show_decimals(input_var, decimals_to_show); | |
let doneObj = { | |
"actions": [{ | |
"type": "set_variable", | |
"data": mapping | |
}] | |
}; | |
done(doneObj); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment