473,698 Members | 2,344 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 1843
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
4435
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
6440
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
4535
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
2952
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
9511
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
5944
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
1148
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
8680
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
8609
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
9169
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
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
7738
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...
1
3052
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
2007
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.