Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

XJS: add currency to price variable that contains no decimals

Posted on 2014-12-24
3
Medium Priority
?
96 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 61

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 40516774
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
ID: 40519590
thanks.
0
 

Author Comment

by:badtz7229
ID: 40540310
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…
Suggested Courses

885 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