473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Currency code help

Hi there! could som1 please help me out? i need toknow if there's
something wrong with this javascript code. 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. Thanks
in advance
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);

}

Jul 14 '06 #1
2 1823
Ra*****@gmail.com wrote:
Hi there! could som1 please help me out? i need toknow if there's
something wrong with this javascript code. 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. Thanks
in advance
You might need to hint JavaScript a bit about the type of your
variables. The value of an input field is usually a String. Use
parseFloat(var) to explicitly convert a string to a floating point
value. Though JavaScript is weakly typed, it does need some help sometimes.

Good luck,
Vincent
Jul 14 '06 #2
JRS: In article <11**********************@75g2000cwc.googlegroups. com>,
dated Fri, 14 Jul 2006 05:36:29 remote, seen in
news:comp.lang.javascript, Ra*****@gmail.com posted :
>
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;
}
fix(1, 3) fails.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: techy techno | last post by:
hii Experts..!! I need someone to tell me where I can get a Currency Converter like http://cconv.textor.com please can someone tell me where I can get it I need it for free + I dont need...
2
by: Willing 2 Learn | last post by:
I'm still having trouble getting my program to do arithmetic in cents(keeping all #'s) then convert the answer in a format of dollars & cents. The main program should add, subtract, scalar...
2
by: Baybars | last post by:
New to access, but to deja.com. Looked through many posts, but can not find a good post for my problem (I believe there is, but my access level didn't allow me to understand). I have a table for...
7
by: zlf | last post by:
1ˇ˘Here is a number. double nu = 123 2ˇ˘Format it with 3ˇ˘The result is "$123" I want to ask how to deformat "$123" to 123 Thx (Currency symbol is not restricted to '$')
1
by: Manuel Canas | last post by:
I'm stuck here guys, need some help. I have a form with a couple fo tabs on it. I load a table in each for each tab. I populate a listbox with a list of names. Then I use currency manager to...
11
by: Adrian | last post by:
Hi I want to use the following declarations but vb dotnet keeps complaining that currency can't be used because it private ? I have tried it in a module and in the declaration pare same error!...
7
by: meenasamy | last post by:
Hi all, i need to create a function that takes three parameters( Original currency, needed currency, amount) i need to convert from the original currency to the needed currency the amount and...
16
by: xjohnx | last post by:
Hi, I'm hoping someone can help me I am quite new to Javascript and have had to create a programme which converts dollars into euros and vice versa, here is my script which is working var...
25
by: mereba | last post by:
Hello My country Ghana is changing its currency. I want to write a small programme in C++ that can covert from the old currency into the new one. I would like this programme to run behind a simple...
1
by: jereesh | last post by:
Hi, I need to display formatted currency values in the My UI currency fields. I would like to know how to do currency formating in javascript . ie when I pass the value and the currency code it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.