ok, i'm trying to get a return value of a float...... but it keeps giving me a load of numbers!
how do i make this interger behave?
the problem is line 39. thanks. -
-
<script language="javascript1.2">
-
-
-
function checkreset()
-
{
-
-
if (confirm('Are you sure you wish to clear the form?'))
-
{
-
return true
-
}
-
return false
-
}
-
-
-
function addnumbers()
-
{
-
-
// This function reads the values from the input boxes
-
// parseFloat converts the input boxes into an integer
-
-
var x,y,result;
-
a = parseFloat(document.form1.abox.value);
-
b = parseFloat(document.form1.bbox.value);
-
c = parseFloat(document.form1.cbox.value);
-
d = parseFloat(document.form1.dbox.value);
-
e = parseFloat(document.form1.ebox.value);
-
f = parseFloat(document.form1.fbox.value);
-
g = parseFloat(document.form1.gbox.value);
-
h = parseFloat(document.form1.hbox.value);
-
i = parseFloat(document.form1.ibox.value);
-
j = parseFloat(document.form1.jbox.value);
-
-
// Then we do the math
-
-
result = a + b + c + d + e + f + g + h + i + j;
-
-
// And write the result straight to the screen
-
document.form1.qbox.value = result;
-
document.form1.totalbox.value = result*10.21;
-
-
-
// As the function has already done the output, we don’t need a return value
-
}
-
</script>
-
-
7 2209 gits 5,390
Expert Mod 4TB
hi ...
nope ... parseFloat() handles the values as float :) ... you may use parseInt() instead ... and multiplying a float produces float again ... so you may use the math-methods to round the value
kind regards
ok, i tried math.round, and that just rounds up the number, which is no good.
so for example, instead of getting a result of €30.630000000000002, i'd like to just get a result of €30.63
how do i do this?
thanks
i'm multiplying a number by 10.21 in javascript, -
document.form1.totalbox.value = "€" + result*10.21;
-
how do i remove the extra zeros?
for example, instead of getting a result of €30.630000000000002, i'd like to just get a result of €30.63
thanks
gits 5,390
Expert Mod 4TB
use the toFixed(); method instead ...
kind regards
gits 5,390
Expert Mod 4TB
threads merged ... please don't double post questions ...
kind regards
threads merged ... please don't double post questions ...
kind regards
no worries, that worked, thanks. -
document.form1.totalbox.value = "€" + (result*10.21).toFixed(2);
-
gits 5,390
Expert Mod 4TB
:) glad to hear that ... post back to the forum anytime you have more questions
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bob Rundle |
last post by:
I would like to get something like this to work...
Type t = FindMyType(); // might be int, float, double, etc
string s = "1233";
object v = t.Parse(s);
This doesn't work of couse, Parse is...
|
by: c0uch |
last post by:
the first and third methods are in a usercontrol object.
txtValue is a TextBox
the float.parse in the if statement on line 3 always works fine.
the second float.parse in the third method is...
|
by: Phil Mc |
last post by:
OK this should be bread and butter, easy to do, but I seem to be going
around in circles and not getting any answer to achieving this simple
task.
I have numbers in string format (they are...
|
by: Python.LeoJay |
last post by:
Dear all,
i need to parse billions of numbers from a file into float numbers for
further calculation.
i'm not satisfied with the speed of atof() function on my machine(i'm
using visual c++ 6)....
|
by: trevor |
last post by:
Incorrect values when using float.Parse(string)
I have discovered a problem with float.Parse(string) not getting values
exactly correct in some circumstances(CSV file source) but in very
similar...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |