# Javascript Currency Calculator

Mar 3, 2007

I am trying to write a currency calculator that can convert between 4 currencies.

I have managed to get as far as to convert from one currency to the other 3 but can not make it convert between the others. Could you please give me some advice how to continue? Code:

## Javascript Calculator Significant Figures

Dec 1, 2006

Basically, i'm in 11th grade and i just got an assignment where im supposed to display 5 prompts, have the user type in numbers, the numbers multiply, and then these numbers are to be displayed in signifcant figures.

The first part is cake. The numbers multiply and everything, and I discovered a function called [var].toPrecision() which gives me significant figures according to the number I ask manually.

Unfortunatly the assignment is much more technically than that. If for example i multiply 1.2222222 * 100 the signifcant figures should end at the lowest decimal, making the answer 122. And if i multiply 33.33 * 33.33 then the lowest decimal is to the hundreths place and the answer is 99.99.

## Reg Expression For Currency

May 20, 2006

I need a regular expression to format U.S. currency as 1,215.25 (commas and decimals)...if it is not already in that format. It should also allow a '-' sign as the first character for negative numbers. I have looked in the FAQ and through this group, plus the net and cannot seem to find the right example.

Any pointers or solutions appreciated. Thanks. I found the belowposted in this group:

<script type="text/javascript">
var RgX = /^\$(d{1,3}(,d{3})*|(d+))(.d{2})?\$/

function NewComma(Q) { Q = String(Q)
return (Q == (Q=Q.replace(RgX, "\$1\$2,\$3"))) ? Q : NewComma(Q)
}

function setFormat(elm){
var frmCurr= NewComma(elm);
}

setFormat(121525);
</script>

## Currency Code

Jul 14, 2006

The code is meant to give the american dollar and european equivalent of a price. i.e when i type
a price in pounds, it gives me the price in dollars and euros.

function fix(thenumber,noplaces){ // returns the number to n decimal
places
var oldnumber=thenumber;
thenumber=thenumber+"0000";
var decpos=thenumber.indexOf(".");
if (decpos==-1) return oldnumber+".00";
decpos=decpos+noplaces+1;
var endstring=thenumber.substring(0,decpos);
return endstring;
}

function convert_currency(){
//var
dollarval=document.converter.original.value/ConversionFactor(document.converter.sourcecurrency .value);
//document.converter.converted.value=fix(dollarval*C onversionFactor(document.converter.targetcurrency. value),2);

var dollarval= document.form.gbp.value;
document.form.usd.value=fix(dollarval*1.85,2);
document.form.eur.value=fix(dollarval*1.46,2);

}

function convert_currency_spec(){
//var
dollarval=document.converter.original.value/ConversionFactor(document.converter.sourcecurrency .value);
//document.converter.converted.value=fix(dollarval*C onversionFactor(document.converter.targetcurrency. value),2);

var dollarval= document.form.special_offer_original_gbp.value;
document.form.special_offer_original_usd.value=fix (dollarval*1.85,2);
document.form.special_offer_original_eur.value=fix (dollarval*1.46,2);

}

## Currency Format

Jul 20, 2005

I found this javascript on javascript.internet.com and it returns a decimal value i.e. 88,999.45 and if I didn't want a decimal value returned what changes should I make. Given the example above I'd like to return 8,899,945. Code:

## Formatting A Number As Currency?

Oct 7, 2010

... or at least adding the commas? I need to format this number as currency. It is within the "flot" code, which is a charting framwork. I dont know anything about javascript at all so bear with me.Here is part of the code, the piece in red calls for the number. This is what I need displayed with commas, so its easy to read. I have found a few examples on the web but I have no idea how to apply them to this code.

var previousPoint = null;
\$("#placeholder").bind("plothover", function (event, pos, item) {
\$("#x").text(pos.x.toFixed(2));

[code]....

## How To Format Currency And Symbols

Nov 5, 2010

I don't really know javascript but I have one to display pricing in a dropdown. Here is what I have. What I would like to change is this.
Currently amounts 0.075 shows as ---> 0.075
4.9999 shows as ---> 4.99
0.1 shows as ---> 0.1
0.095 shows as ---> 0.095

I would like to get the above to show as follows:
0.075 shows as ---> 7.5
4.9999 shows as ---> \$4.99
0.1 shows as ---> 10
0.095 shows as ---> 9.5

The first column (pricing data) is a standard format I cannot change so it must stay that way. Here is my code as it is now.
<script type="text/javascript">
function showrate(strValue){
var objLabel = document.getElementById("lblMessage");
if(objLabel.childNodes.length < 1) {
var objNodeValue = document.createTextNode(strValue);
objLabel.appendChild(objNodeValue); .....

## Currency Javascipt Function

Oct 8, 2005

Is there a currency javascipt function that will automatically put the \$ in and 2 decimals? Example:

7.99 becomes \$7.99
8 becomes \$8.00
2 * 8 becomes \$16.00

## Can't Sum \$ Currency In HTML Table?

Aug 12, 2009

<!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.0

Use code tags when posting your code. Code tags are used like so =>

## Formatting Currency Data

May 4, 2006

Anybody knows javascript which doers formatting of a text box in the following format
999,999,999,999

## Formatting For Currency And Values That = Zero As Blank?

Aug 11, 2011

(previously posted in the wrong forum and re-posted in this one)Hi there, I have scoured the internet looking for the right code but to no avail. I have gotten as far as totaling up my form but now want to format the amounts and total as currency and also want the values that = 0 to just be blank. I have tried to use the code from other solutions (posted on the net) but I just think it is over my head because I cant figure it out. I thought I was close a few times but wasn't able to bring it on home. One of my issues is using somebody's code and not knowing where in my code to place it have tried exhaustively to solve on my own but there is a point.

## Formatting To Currency And Then Checking If Its Greater

Nov 29, 2011

Im in the process of creating a auction site for charity, im working on the last page which allows the user to enter a bid i have this javascript function that i have been working on to try and achieve the following.the user enters a bid use javascript to check to make sure its greater then and not equal to the current price simple right?where i enter 10.50 and the current price is 9.99 i get the error message saying needs to be greater,

## Output To Two Decimal Places As Its Currency

Mar 16, 2010

I am new to javascript and I am attempting to output to two decimal places as its currency. As an example it currently outputs as 127.1 instead of 127.10.

[Code]....

## Total Currency Form Cells With \$?

Sep 1, 2011

I have an online form with 6 cells formatted for \$ whether user types \$ or not. I have a total cell (hidden) that needs to total those 6 cells. I always get the NaN in the total cell. I have tried it without auto \$ formatting, but if user inputs \$, than the NaN will appear. Is there no way to total cells that have or may have \$s?

## JQuery :: Make Sure Field Is Currency?

Sep 22, 2010

I have a text field with id=amount.

How can I use JQuery to check that it only contains the digit 1234567890 and one and only one "." symbol?

## JQuery :: Removing Currency Symbols From A String?

Oct 13, 2011

How can I remove the currency symbols from a string, for example I could be dealing with strings like -

\$54.32
€54.00
£20.11

Is there a single function that can remove the currency symbol no matter what it is?

## Create A Currency Converter Using A Drop Down Menu?

May 22, 2010

I need to create a currency converter using a drop down menu. Firstly i needed to do a regular expressions check to make sure only numerics are entered and I got that. The one thing im pretty confused on is how to do the calculations in the actual function.

<html>
<style type ="text/css">
@import url(style.css);

[code]....

## Formatting For Currency And Remove Null Values

Aug 10, 2011

I have scoured the internet looking for the right code but to no avail. I have gotten as far as totaling up my form but now want to format the amounts and total as currency and also want to strip out the values that =0. I have tried to use the code from other solutions (posted on the net) but I just think it is over my head because I cant figure it out. I thought I was close a few times but wasn't able to bring it on home. One of my issues is using somebody's code and not knowing where in my code to place it. [URL]

## Change Input To Currency Format After Calculation?

Mar 15, 2011

I have been working on this code for a few days now and it works. Or at least it appears to be working. I would like to have the tot 1, tot 2, tot 3 return with currency formatting. Is there a way to add something to my code to accomplish this?

<html>
<script type="text/javascript" src="autoCurrency.js"></script>

[code]....

## (validating Fields) With Reg Expression For These Currency / Price Values

May 20, 2009

(validating fields) with reg expression for these currency/price values:

1. 100,000 ,0, 1,000 , 1,000,000 (should only have commas , no decimals) imean for all number formats
2. 1,000,000+ , 100,000+ , 0+ but not '100+00,' (for all number formats with + sign after that)

## Working On An Mpg Calculator ?

Oct 4, 2009

I am working on an Mpg calculator and I am stuck.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

I have a mistake when it is suppose to calculate.

## Make A Calculator App?

Mar 25, 2011

I'm trying to make a calculator app; with a few differences. I have a text field with a numberpad below it, I got the numbers to show up in the text field, but am unsure as to how when I hit the enter button - it would store them in a variable?...I am also wondering as to how it would store current value and then allow me to input another value(maybe on the next page) and either subtract or add to it(the first value that is stored).I am also wondering how to get a decimal point in place(need it for currency).

Here is my code:

<html>
<script type = "text/javascript">

[code].....

## Creating A Less Than Or More Than Calculator?

Dec 2, 2011

I have the last assignment that she wants us to do and I had to pull up another assignment that she wanted us to build upon( which is one of those coding without anything advance)

<html>
<title>

[code]....

now she wants us to do max <beta and then name the variables with if a<b and I don't know if I put that in the concatenation or what to name my variables!

## Price Calculator

Jan 4, 2007

I am trying to create a price calculator that automatically calculates the price of custom made picture frame. I got an equation that finds the square area of the frame by multiplying the perimeter (2*length*width) by the thickness (which the user can choose from 1.5", 2" or 3"). Then it multiplies it by a decimal number (0.27 if the frame is 1.5" thick, 0.23 if its 2" thick, and 0.18 if its 3" thick). Then it adds a \$5 custom made fee to the final answer. But when I save it to an html file and load it in Internet Explorer, it doesn't calculate. Code:

## Field Calculator

Jul 26, 2007

I'm having some problems with a calculator that I'm working on and am stumped on a particular situation regarding adding additional script and how it should be written. I've searched the forum and the web and just cant locate a viable solution. Code:

## Basic Calculator

Dec 6, 2003

I know there is a million of them but here's a little calculator script I made just for kicks. Feedback is always appreciated, good or bad.

I think I did a pretty good job of mirroring the windows calculator functionality.

Basic keys are mapped (optionally) to the keyboard.

<html>
<title>Web Calculator</title>
<style type="text/css">
table
{
text-align:center;
background-color:#e5e5c5;
}

.button
{
width:55px;
font-weight:bold;
background-color:lightblue;
color:#333399;
}

.functbut
{
width:55px;
font-weight:bold;
background-color:lightblue;
color:red;
}

.back
{
width:115px;
font-weight:bold;
background-color:lightblue;
color:red;
}

{
color:#333399;
}

#display
{
text-align:right;
}
</style>
<script type="text/javascript">
var find=document.getElementById;
var temp=0;
var total=0;
var which=0;
var m=0;

function Mplus()
{
m=parseFloat(find('display').value) + m;
find('memory1').value="M+*";
}

function Mclear()
{
m=0;
find('memory1').value="M+";
}

function Mrecall()
{
find('display').value=m;
}

function Mreplace()
{
m=find('display').value;
}

function showMe(num)
{
if(temp==0)
{
find('display').value=num;
temp=1;
}
else
{
find('display').value+=num;
}
}

function calcEm(num)
{
str=parseFloat(find('display').value);
if(which==0)
{
total=find('display').value;
temp=0;
which=num;
}
else if(which==1)
{
find('display').value=parseFloat(total)+ str;
total=find('display').value;
which=num;
temp=0;
}
else if(which==2)
{
find('display').value=parseFloat(total) * str;
total=find('display').value;
which=num;
temp=0;
}
else if(which==3)
{
find('display').value=parseFloat(total) / str;
total=find('display').value;
which=num;
temp=0;
}
else if(which==4)
{
find('display').value=parseFloat(total) - str;
total=find('display').value;
which=num;
temp=0;
}

}

function clearAll()
{
find('display').value=0;
which=0;
temp=0;
total=0;
}

function clearDisplay()
{
find('display').value="0"
temp=0;
}

function fractIt()
{
find('display').value=(1) / str;
}

function getPerc()
{
var d=find('display').value=str / 100;
calcEm(0);
}

function backSpace()
{
find('display').value=find('display').value.substring("0",find('display').value.length-1);
}

function getRoot()
{
find('display').value=Math.sqrt(find('display').value);
}

function invertIt()
{
var w=find('display').value.indexOf("-");
if(w==-1)
{
find('display').value="-" + find('display').value
}
else
{
find('display').value=find('display').value.substring("1",find('display').value.length);
}
}

function keyHandler()
{
keys=new Array();
keys[97]=("1");
keys[98]=("2");
keys[99]=("3");
keys[100]=("4");
keys[101]=("5");
keys[102]=("6");
keys[103]=("7");
keys[104]=("8");
keys[105]=("9");
keys[96]=("0");
keys[13]=("equal");
keys[107]=("plus");
keys[110]=("dot");
keys[109]=("minus");
keys[106]=("times");
keys[111]=("divide");
keys[110]=("dot");
keys[8]=("back");
keys[27]=("clear");

kc=window.event.keyCode;

if(keys[kc]!=undefined)
{
cColor('#333399');
setTimeout('cColor("lightblue")',100);
find(keys[kc]).click();
}
return false;
}
function cColor(bcolor)
{
find(keys[kc]).style.background=bcolor;
}

function keyOnOff()
{
var b=find('keychoice').checked
if(b==true)
{
document.onkeydown=keyHandler;
}
else
{
document.onkeydown="";
}
}
function checkHandler()
{
var e=find('keychoice').checked
if(e==false)
{
e=true;
}
else
{
e=false;
}
keyOnOff();
}

</script>
<body>
<table cellspacing="0" border="1">
<tr>
<td colspan="6"><input type="text" size="43" id="display" value="0."></td>
</tr>
<tr>
<td colspan="2"><input type="button" value="Backspace" id="back" class="back" onclick="backSpace()"></td>
<td colspan="2"><input type="button" id="ce" value="CE" class="back" onclick="clearDisplay()"></td>
<td colspan="2"><input type="button" id="clear" value="C" class="back" onclick="clearAll()"></td>
</tr>
<tr>
<td><input type="button" class="functbut" value="MC" onclick="Mclear();"></td>
<td><input type="button" class="button" id="7" value="7" onclick="showMe(&#397;')"></td>
<td><input type="button" class="button" id="8" value="8" onclick="showMe(&#398;')"></td>
<td><input type="button" class="button" id="9" value="9" onclick="showMe(&#399;')"></td>
<td><input type="button" class="functbut" id="divide" value="/" onclick="calcEm(3)"></td>
<td><input type="button" class="button" id="sqrt" value="sqrt" onclick="getRoot();"></td>
</tr>
<tr>
<td><input type="button" class="functbut" value="MR" onclick="Mrecall();"></td>
<td><input type="button" class="button" id="4" value="4" onclick="showMe(&#394;')"></td>
<td><input type="button" class="button" id="5" value="5" onclick="showMe(&#395;')"></td>
<td><input type="button" class="button" id="6" value="6" onclick="showMe(&#396;')"></td>
<td><input type="button" class="functbut" id="times" value="*" onclick="calcEm(2)"></td>
<td><input type="button" class="button" id="perc" value="%" onclick="getPerc()"></td>
</tr>
<tr>
<td><input type="button" class="functbut" value="MS" onclick="Mreplace();"></td>
<td><input type="button" class="button" id="1" value="1" onclick="showMe(&#391;')"></td>
<td><input type="button" class="button" id="2" value="2" onclick="showMe(&#392;')"></td>
<td><input type="button" class="button" id="3" value="3" onclick="showMe(&#393;')"></td>
<td><input type="button" class="functbut" id="minus" value="-" onclick="calcEm(4)"></td>
<td><input type="button" class="button" id="x" value="1/x" onclick="fractIt()"></td>
</tr>
<tr>
<td><input type="button" class="functbut" value="M+" id="memory1" onclick="Mplus();"></td>
<td><input type="button" class="button" id="0" value="0" onclick="showMe(&#390;')"></td>
<td><input type="button" class="button" id="flop" value="+/-" onclick="invertIt()"></td>
<td><input type="button" class="button" id="dot" value="." onclick="showMe(this.value)"></td>
<td><input type="button" class="functbut" id="plus" value="+" onclick="calcEm(1)"></td>
<td><input type="button" class="functbut" id="equal" value="=" onclick="calcEm(0)"></td>
</tr>
<tr>
id="keychoice" onclick="checkHandler();keyOnOff();"></td>
</tr>
</table>

</body>
</html>

Happy Calculating...