Solved

XJS: add currency to price variable that contains no decimals

Posted on 2014-12-24
3
78 Views
Last Modified: 2015-01-09
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
Comment
Question by:badtz7229
  • 2
3 Comments
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
Comment Utility
here:

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

alert("before : " + price);
price = price / Math.pow(10,NumberOfDecimals);
alert("after : " + price);
</script>

Open in new window

0
 

Author Closing Comment

by:badtz7229
Comment Utility
thanks.
0
 

Author Comment

by:badtz7229
Comment Utility
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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now