Update: The below code is now working but I need a way to round the value in Text155 to only two decimal places. Can someone help?
Hi, I have a javascript function that is returning NaN in Text155 field. Can someone tell me what I'm doing wrong? If you haven't already guessed, I am also new to the Javascript world. Thanks! -
<script language="Javascript">
-
function sum()
-
{
-
document.form1.Text155.value = (parseInt(document.form1.Text52.value) + parseInt(document.form1.Text53.value) + parseInt(document.form1.Text54.value) + parseInt(document.form1.Text55.value) + parseInt(document.form1.Text56.value));
-
return false;
-
}
-
-
function FP_callJS() {//v1.0
-
eval(arguments[0]);
-
}
-
</script>
-
20 6644 gits 5,390
Expert Mod 4TB
hi ...
you may use: - var val = 58.567;
-
-
// round val to two decimals
-
var res = Math.round(val*100)/100;
-
-
// res is now 58.57
kind regards
hi ...
you may use: - var val = 58.567;
-
-
// round val to two decimals
-
var res = Math.round(val*100)/100;
-
-
// res is now 58.57
kind regards
Sorry for being a pain but could you show me in my code above where to put this? Thanks.
gits 5,390
Expert Mod 4TB
let me give you an example for how to do that :) - <script type="text/javascript">
-
function get_sum() {
-
var frm = document.form1;
-
var outp = frm.Text155.value;
-
var res = 0;
-
-
for (var i = 2; i < 7; i++) {
-
res += parseInt(frm['Text5' + i].value, 10);
-
}
-
-
outp = Math.round(res*100)/100;
-
-
return false;
-
}
-
</script>
-
kind regards
Got it...you're the best. Thank you.
gits 5,390
Expert Mod 4TB
no problem ... glad to hear you got it working ... post back to the forum anytime you have more questions :)
kind regards
hbella, you posted this using the Report button:
hi gits
i need to change fields into R 000,000,000.00 but for the display, data
patterns i use ($Z,Z9.99) but after execution it allows/ outputs only
four digits.pls help!!
greeting and thanx
Please use the Reply link/button in future (the one to the far right). Thanks.
I am very new to this. I'm working on a website: http://www.nhtpc.com/tools.htm where i'm trying to get the calculations to round to 2 decimal places where as right now it's showing 10.
Below is the code i'm using: - <form>
-
<table width="98%" border="0" cellpadding="0" cellspacing="0">
-
<tr>
-
<td width="36%"><div align="right">Degrees F: </FONT>
-
<input type="text" name="F" value="32"
-
onchange="C.value = 100/(212-32) * (this.value - 32 )" />
-
</div></td>
-
<td width="43%" align="right">to Degrees C: </FONT>
-
<input name="C" type="text"
-
onchange="F.value = (212-32)/100 * this.value + 32 " value="0.0" /></td>
-
<td width="21%"> </td>
-
</tr>
-
</table>
-
</form>
Any suggestions would be much appreciated.
gits 5,390
Expert Mod 4TB
in case you always want to display the 2 decimals, then you may use the toFixed() method ...
kind regards
Thank you for your reply. Where do I paste this? ...and do I paste this entire block? - var n = 12345.6789;
-
-
n.toFixed(); // Returns 12346: note rounding, no fractional part
-
n.toFixed(1); // Returns 12345.7: note rounding
-
n.toFixed(6); // Returns 12345.678900: note added zeros
-
(1.23e+20).toFixed(2); // Returns 123000000000000000000.00
-
(1.23e-10).toFixed(2) // Returns 0.00
Thank You!
you do not paste this code block. that's just for demonstration how to use it.
another example: - var n = 10.234;
-
var x = n.toFixed(2); // x is now 10.23
I greatly appreciate everyone who has posted for this topic, but I don't even know enough to know what to do with that.
Thanks for your time.
gits 5,390
Expert Mod 4TB
you need to do something like this: - F.value = ((212-32)/100 * this.value + 32).toFixed(2);
Thank You gits..
I believe I am still doing something wrong. It not rounding up, and it's still giving me lots of numberes after the decimal. Please see code below. - <form>
-
<table width="98%" border="0" cellpadding="0" cellspacing="0">
-
<tr>
-
<td width="36%"><div align="right">Degrees F: </FONT>
-
<input type="text" name="F" value="32"
-
onchange="C.value = 100/(212-32) * (this.value - 32 ) .toFixed(2);" />
-
</div></td>
-
<td width="43%" align="right">to Degrees C: </FONT>
-
<input name="C" type="text"
-
onchange="F.value = ((212-32)/100 * this.value + 32).toFixed(2);" /></td>
-
<td width="21%"> </td>
-
</tr>
-
</table>
-
</form>
gits 5,390
Expert Mod 4TB
is it in the C-field (line 6 in your above code)? you need to set the brackets like in the example ...
kind regards
Ok some of this worked. It works from C Degrees to F Degrees, but not the other way around. Could you tell me what I'm doing wrong in the first half of this code? - <form>
-
<table width="98%" border="0" cellpadding="0" cellspacing="0">
-
<tr>
-
<td width="36%"><div align="right">Degrees F: </FONT>
-
<input type="text" name="F" value="32"
-
onchange="C.value = 100/(212-32) * (this.value - 32).toFixed(2); " />
-
</div></td>
-
<td width="43%" align="right">to Degrees C: </FONT>
-
<input name="C" type="text"
-
onchange="F.value = ((212-32)/100 * this.value + 32).toFixed(2); " value="0.0" /></td>
-
<td width="21%"> </td>
-
</tr>
-
</table>
-
</form>
Thank You!
gits 5,390
Expert Mod 4TB
as i said, the brackets are the problem: - C.value = (100/(212-32) * (this.value - 32)).toFixed(2);
Thank You! It works perfectly. I appreciate your time and patience with me. I wasn't sure where to put the second bracket on the first half of the code.
gits 5,390
Expert Mod 4TB
as you should see now, that you have to set the brackets according to the value that you want to have 'Fixed' ... the toFixed() method is used on numeric-values and casts the value to a string with the passed number of decimals ...
I understand now. Thank you for your time. You are a genius!
gits 5,390
Expert Mod 4TB
nope ;) ... but in case you have more questions just post back to the forum ;)
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Joe M Blow |
last post by:
Hi evreyone
I just want to kno how to make my value (a float) and round it off to two
decimal places
Thanks alot
Ty
|
by: Brent Bortnick |
last post by:
Does anyone know how to find out the number of decimal
places a number has. I need this info so that i can round
to 3 decimal places if the number has 3 decimal places or
to 2 decimal places if...
|
by: Gizmo |
last post by:
Hi there i was wondering if any one new to a function that rounds up a float
to so many decimal places. I have a number in bytes and converting it to
mb's and gb's but once its converted i need to...
|
by: John Bentley |
last post by:
John Bentley writes at this level:
If we think about our savings accounts then division never comes in (as far as
I can see). We deposit and withdraw exact amounts most of the time. Occasionaly...
|
by: Ron |
last post by:
Greetings,
int i = 1, j = 6;
double k = (double)i/j;
Console.WriteLine(k.ToString());
Console.WriteLine(string.Format(k.ToString(), "0.00"));
both yield 0.166666666666667
how can I make...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I convert a Number into a String with
exactly 2 decimal places?...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I convert a Number into a String with
exactly 2 decimal places?...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I format a Number as a String with
exactly 2 decimal places?...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
| |