• Status: Solved
• Priority: Medium
• Security: Public
• Views: 102

# XJS: add currency to price variable that contains no decimals

I have
var price =2799
var NumberOfDecimals = nodeCurrencyCode.GetAttribute("NumberOfDecimals");

i want to update price such that it conforms to the NumberOfDecimals present.

ie. if NumberOfDecimals == 2 then price = 27.99
0
• 2
1 Solution

Sr. System AnalystCommented:
here:

``````<script>
var price =2799
var NumberOfDecimals = 2;
//var NumberOfDecimals = nodeCurrencyCode.GetAttribute("NumberOfDecimals");

price = price / Math.pow(10,NumberOfDecimals);
</script>
``````
0

Author Commented:
thanks.
0

Author Commented:
quick question on this, if var price =2900 or var price =3040 your solution doesn't take into account the trailing zeros.
instead it outputs 29 and 30.4
I'd like 29.00 and 30.40

how can i do that?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.