473,738 Members | 9,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,n oplaces){ // returns the number to n decimal
places
var oldnumber=thenu mber;
thenumber=thenu mber+"0000";
var decpos=thenumbe r.indexOf(".");
if (decpos==-1) return oldnumber+".00" ;
decpos=decpos+n oplaces+1;
var endstring=thenu mber.substring( 0,decpos);
return endstring;
}

function convert_currenc y(){
//var
dollarval=docum ent.converter.o riginal.value/ConversionFacto r(document.conv erter.sourcecur rency.value);
//document.conver ter.converted.v alue=fix(dollar val*ConversionF actor(document. converter.targe tcurrency.value ),2);

var dollarval= document.form.g bp.value;
document.form.u sd.value=fix(do llarval*1.85,2) ;
document.form.e ur.value=fix(do llarval*1.46,2) ;

}
function convert_currenc y_spec(){
//var
dollarval=docum ent.converter.o riginal.value/ConversionFacto r(document.conv erter.sourcecur rency.value);
//document.conver ter.converted.v alue=fix(dollar val*ConversionF actor(document. converter.targe tcurrency.value ),2);

var dollarval= document.form.s pecial_offer_or iginal_gbp.valu e;
document.form.s pecial_offer_or iginal_usd.valu e=fix(dollarval *1.85,2);
document.form.s pecial_offer_or iginal_eur.valu e=fix(dollarval *1.46,2);

}

Jul 14 '06 #1
2 1847
Ra*****@gmail.c om 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************ **********@75g2 000cwc.googlegr oups.com>,
dated Fri, 14 Jul 2006 05:36:29 remote, seen in
news:comp.lang. javascript, Ra*****@gmail.c om posted :
>
function fix(thenumber,n oplaces){ // returns the number to n decimal
places
var oldnumber=thenu mber;
thenumber=then umber+"0000";
var decpos=thenumbe r.indexOf(".");
if (decpos==-1) return oldnumber+".00" ;
decpos=decpos+ noplaces+1;
var endstring=thenu mber.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.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
4438
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 any link of the co. the code for this is here but when I change it it just says unauthorize
2
574
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 multiply(by int)& show, have a constructor w/ & w/out arguments. Header file should have private data & all 6 functions from above.Class definition file should implement my ADT class. What I have so far: Main program #include "jahcurrency.h" #include...
2
6444
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 cash flow of a shop. Forreign currencies are accepted. I built the tables accordingly: CURRENCY TYPE (USD, EURO, POUND ETC), AMOUNT OF THE CURRENCY. RATE FOR LOCAL CURRENCY and LOCAL CURRENCY VALUE. When I entered the type of currency (eg USD),...
7
4539
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
1354
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 manipulate the datatables. This is my issue here, whenever I click on a name on the listbox the first currency manager currentchanged event fires, that works ok. Now I cannot find a way to pass the current selected item from the first currency...
11
2957
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! Private Declare Function QueryPerformanceFrequency Lib "kernel32" (ByVal
7
4069
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 return the new amount in the needed currency, I need this function to work real time (obtaining real time currency exchange rates), any ideas???
16
9521
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 currency; var amountEntered; currency = window.prompt('Please enter 0 to convert from Dollars to euros and 1 to convert form euros to dollars',''); currency = parseFloat(currency); while (currency < 0 || currency > 1) { currency =...
25
5950
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 calculator- looking interface. I'm quite new to C++, and I would need some help. Please any suggestion is welcome :) The following is what I have been able to do so far:
1
1153
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 should display the formatted currency in the field with currency symbol. the Code will be like USD, EURO etc. but when it get displayed it should display the curresponding sysmbol can any body help me in this Regard Regards
0
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.