Solved

XJS: add currency to price variable that contains no decimals

Posted on 2014-12-24
3
85 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:
Huseyin KAHRAMAN earned 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Drop down list show all elements but disabled for selection 6 35
Sending ASP to server side 8 32
Calculating percentage 2 29
sort Multi-dimensional array 6 12
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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

749 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