Skip to content

Instantly share code, notes, and snippets.

@juanbenitez
Created April 29, 2020 11:02
Show Gist options
  • Save juanbenitez/7d41ce71be4efc8ea921bbd146eab955 to your computer and use it in GitHub Desktop.
Save juanbenitez/7d41ce71be4efc8ea921bbd146eab955 to your computer and use it in GitHub Desktop.
//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