1. Registered User
Join Date
Apr 2014
Posts
4

## help please to calculate the % on my script

hi

i am quite new on this ... i am struggling with the following

i need to calculate the 3% if the amount in Pounds is more than £100 if its less the result will only be £3

this is my script right now

<html>
<script>
function ConvertToPound(val, from) {
if (from == 0) { response = val; }
if (from == 1) { response = roundNumber(val/3255.0000,2); }
if (from == 2) { response = roundNumber(val/1.6500,2); }
if (from == 3) { response = roundNumber(val/3.6300,2); }
return response;
}
function ConvertCurrency(from, to, val, textT, textF) {
var response = "";

newcurrency = ConvertToPound(val, from);
if (to == 1) { newcurrency = roundNumber(newcurrency*3255.0000,2); }
if (to == 2) { newcurrency = roundNumber(newcurrency*1.6500,2); }
if (to == 3) { newcurrency = roundNumber(newcurrency*3.6300,2); }
response = val+"<b> "+textF+" = </b>"+newcurrency+"<b> "+textT+"</b>";
document.getElementById("showcurrency").innerHTML = response;
}
function roundNumber(num, dec) {
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}
</script>
<b>Convert </b><input type="text" value="0.00" id="currency">
<b>From </b>
<select id="from">
<option value="0">£ POUNDS</option>
<option value="1">COLOMBIA</option>
<option value="3">BRASIL</option>
</select>
<b>To </b>
<select id="to">
<option value="0">£ POUNDS</option>
<option value="1">COLOMBIA</option>
<option value="3">BRASIL</option>
</select>
<input type="button" value="Convert" onclick="ConvertCurrency(document.getElementById('from').value, document.getElementById('to').value, document.getElementById('currency').value, document.getElementById('to').options[document.getElementById('to').selectedIndex].text, document.getElementById('from').options[document.getElementById('from').selectedIndex].text);">
<br>
<div id="showcurrency"></div>
</html>

any help will be really appreciated

thank you

2. Registered User
Join Date
Feb 2014
Location
Posts
155
Try something like this (although I'm not sure why it has to be 3 if the value is less than 100):

Code:
```if (from == 0) {
if(val >= 100) {
response = val * 0.03;
} else {
response = 3;
}
}```
Just to let you know, you're not using HTML5 and have coding errors (run it through the HTML validator). Also, symbols such as £ don't display correctly on all devices (i.e. I'm getting Â£).

3. Registered User
Join Date
Apr 2014
Posts
4
Originally Posted by Error404
Try something like this (although I'm not sure why it has to be 3 if the value is less than 100):

Code:
```if (from == 0) {
if(val >= 100) {
response = val * 0.03;
} else {
response = 3;
}
}```
Just to let you know, you're not using HTML5 and have coding errors (run it through the HTML validator). Also, symbols such as £ don't display correctly on all devices (i.e. I'm getting Â£).
HI can you please tell me where to put the code please and thank you for your help

4. Registered User
Join Date
Feb 2014
Location
Posts
155
In the ConvertToPound function, replace

Code:
`if (from == 0) { response = val; }`
with the code I provided.

If you wrote the script you initially provided, you shouldn't have a problem writing a minor change.

5. Registered User
Join Date
Apr 2014
Posts
4
Originally Posted by Error404
In the ConvertToPound function, replace

Code:
`if (from == 0) { response = val; }`
with the code I provided.

If you wrote the script you initially provided, you shouldn't have a problem writing a minor change.
thank you for your help ---
i have replaced it before as you mentioned but it calculates wrongly

what im trying to do is the following but im lost

say
if i enter 100 from £ POUNDS (1) TO COLOMBIA (3255)

THE ANSWER WILL BE 100 - 3 = 97 * 3255 (COLOMBIA) = 315735

if i enter 150 from POUNDS (1) TO COLOMBIA (3255)

THE ANSWER WILL BE -3% of 150 = 150-4.50= 145.50 * 3255 (COLOMBIA) = 473602

BUT ITS GIVING ME A COMPLETELY DIFFERENT RESULT

thats why im lost

sorry im really stuck

6. Registered User
Join Date
Apr 2014
Posts
4
i am trying to learn how to use scripts since i have always worked with powerbuilder sorry