There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox firewall freezes freezing hard drive hardware hijackthis internet internet explorer itunes laptop malware motherboard mouse network networking outlook outlook 2007 popups power printer problem ram router screen slow sound trojan usb virus vista vista 32-bit windows windows xp winxp wireless
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Javascript - Decimals


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
drdrew1469's Avatar
Senior Member with 436 posts.
 
Join Date: Nov 2000
Location: PA
Experience: God
28-Jan-2004, 03:57 PM #1
Javascript - Decimals
In my script everything is calculating and working correctly; however, if I put a decimal in the input box it does not change the output which leads me to believe it is maybe rounding when it shouldn't. Could you please point me in the right direction. Below is an example and my code.

Thanks,

Drew

examples with current code:

(12 - (10 - .5)) / 2 = 1.25

(12.5 - (10 - .5)) / 2 = 1.25 = 1.5

<SCRIPT>
function calc()
{
var val1, val2, val3, val4
var result1, result2, result3, result4, result5, result6
val1 = parseInt(document.Form1.val1.value)
val2 = parseInt(document.Form1.val2.value)
val3 = parseInt(document.Form1.val3.value)
val4 = parseInt(document.Form1.val4.value)
{
result = (val1 - (val2 - .5)) / 2
}
document.Form1.result1.value = result
{
result = (val3 - (val4 - .5)) / 2
}
document.Form1.result2.value = result
{
result = (val1 - val2) / 2
}
document.Form1.result3.value = result
{
result = (val3 - val4) / 2
}
document.Form1.result4.value = result
{
result = (val1 - (val2 + .5)) / 2
}
document.Form1.result5.value = result
{
result = (val3 - (val4 + .5)) / 2
}
document.Form1.result6.value = result
}
</SCRIPT>
__________________
Please help me as I am attempting to (re)gain my (in)sanity.
bassetman's Avatar
Computer Specs
Moderator with 48,096 posts.
 
Join Date: Jun 2001
Location: Great White North (WI)
Experience: Getting somewhere I hope
28-Jan-2004, 03:59 PM #2
Just a WAG, could try making your .5 a .50 or .500 and see if that value set the parameters for rounding!
drdrew1469's Avatar
Senior Member with 436 posts.
 
Join Date: Nov 2000
Location: PA
Experience: God
28-Jan-2004, 04:01 PM #3
Thanks for the quick reply. Just tried it, no go.

Thanks,

Drew
bassetman's Avatar
Computer Specs
Moderator with 48,096 posts.
 
Join Date: Jun 2001
Location: Great White North (WI)
Experience: Getting somewhere I hope
28-Jan-2004, 04:04 PM #4
Darn, I thought maybe I could pull that one out of my arse!
Sorry no more ideas.
drdrew1469's Avatar
Senior Member with 436 posts.
 
Join Date: Nov 2000
Location: PA
Experience: God
28-Jan-2004, 04:06 PM #5
Thanks for the free thought! I am hard pressed to find this anywhere.

Thanks,

Drew
bassetman's Avatar
Computer Specs
Moderator with 48,096 posts.
 
Join Date: Jun 2001
Location: Great White North (WI)
Experience: Getting somewhere I hope
28-Jan-2004, 04:07 PM #6
Ok, did a google and found this
http://forums.devshed.com/t95424/s.html

Please let me know if that works.
drdrew1469's Avatar
Senior Member with 436 posts.
 
Join Date: Nov 2000
Location: PA
Experience: God
28-Jan-2004, 04:10 PM #7
Wow. That's all I can say. I'll have to pick that apart to see what exactly is goin on. Thanks for the link.

Thanks,

Drew
bassetman's Avatar
Computer Specs
Moderator with 48,096 posts.
 
Join Date: Jun 2001
Location: Great White North (WI)
Experience: Getting somewhere I hope
28-Jan-2004, 04:12 PM #8
Here's one that may be of more help
http://spiderpro.com/bu/bujvsh002.html
Rockn's Avatar
Computer Specs
Distinguished Member with 17,888 posts.
 
Join Date: Jul 2001
Location: Mexico of the North, MN
Experience: Disenfranchised American Male
28-Jan-2004, 04:16 PM #9
If it were rounding it wouldn't round down. Clear your form contents prior to trying it again. Sounds like the old values are remaining and calculating again. I also didn't see an End Function
bassetman's Avatar
Computer Specs
Moderator with 48,096 posts.
 
Join Date: Jun 2001
Location: Great White North (WI)
Experience: Getting somewhere I hope
28-Jan-2004, 04:17 PM #10
In my last link I think it isn here.
PHP Code:
<SCRIPT  type="text/javascript" >
<!-- 
hide for non JS browsers
function fdp(n,d){
    var 
xx n.indexOf('.')
    var 
n.length
    
var zstr '0000000000000000000000' 
Oh, and you're welcome.
drdrew1469's Avatar
Senior Member with 436 posts.
 
Join Date: Nov 2000
Location: PA
Experience: God
28-Jan-2004, 04:22 PM #11
That's starting to look more like what I need, thanks. Just wondering if maybe the input boxes have something to do with it? Not likely I guess, I have no vaildation set on them.

Rockn, that's just a snip, everything is here, I thought I was missing something in my vars or something. The form is cleared each time before calculation.

Thanks,

Drew
__________________
Please help me as I am attempting to (re)gain my (in)sanity.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:57 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.