/    Sign up×
Community /Pin to ProfileBookmark

my script won’t accept DECIMALS!

why doesn’t this script accept decimals… anyone have a solution?

i need it to be able to hold a max ammount of $1000.00 with 2 decimal places

[CODE] <html>

<head>

<title>Untitled Document</title>

<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″>

<script language=”JavaScript”>

function addit()

{

document.summing.s.value = parseInt(document.summing.a.value) + parseInt(document.summing.b.value) + parseInt(document.summing.c.value) + parseInt(document.summing.d.value) + parseInt(document.summing.e.value) + parseInt(document.summing.f.value)

}

function subit()

{

document.summing.ms.value = parseInt(document.summing.s.value) – parseInt(document.summing.tp.value)

}

function clearform()

{

document.summing.a.value= “0”;

document.summing.b.value= “0”;

document.summing.c.value= “0”;

document.summing.d.value= “0”;

document.summing.e.value= “0”;

document.summing.f.value= “0”;

document.summing.s.value= “0”;

document.summing.ms.value= “0”;

}

</script>

</head>

<body bgcolor=”#99FF99″>

<font color=”#CC0000″>Adding two numbers</font><td width=”79%” style=”vertical-align:top” height=”317″><table class=”section” border=”1″ width=”586″ height=”1″>

<tr>

<td width=”271″ height=”22″>

<font color=”#008000″>Current Payment</font></td>

<td width=”299″ height=”22″>

<font color=”#008000″>Splash Plumbing Prices</font></td>

</tr>

<tr>

<td class=”section-body” height=”1″ width=”271″>

<p>

<div style=”width: 100%; height: 100%”>

<form name=”summing”>

Enter the amount you pay monthly for your plumbing<p>a Text<br>

$<input type=”text” name=”a” size=13 maxlength=”6″ value=”0″> <br>

b Text<br>

$<!–webbot bot=”Validation” s-data-type=”Number” s-number-separators=”,.” i-maximum-length=”6″ –><input type=”text” name=”b” size=”13″ maxlength=”6″ value=”0″><br>

c Text<br>

$<input type=”text” name=”c” size=”13″ maxlength=”6″ value=”0″><br>

d Text<br>

$<input type=”text” name=”d” size=”13″ maxlength=”6″ value=”0″><br>

e Text<br>

$<input type=”text” name=”e” size=”13″ maxlength=”6″ value=”0″><br>

f Text<br>

$<input type=”text” name=”f” size=”13″ maxlength=”6″ value=”0″><br>

<br>

<br>

<input type=”button” value =”Calculate Total” name=”Submit” onClick=”addit()”>&nbsp;

<input type=”button” name=”Submit2″ value=”Reset” onClick=”clearform()”><br>

Total:&nbsp;<br>

$<input type=”text” name=”s” size=”10″ maxlength=”5″ value=”0″ style=”background-color: #99FF99″ border=”0″></span>&nbsp;&nbsp;<br>

&nbsp;</p>

</div>

</p>

</td>

<td class=”section-body” height=”1″ width=”96″>

<p>

<p>

</p>

<p></p>

<div style=”width: 295; height: 471″><p>a Test<br>

$ 0.00<br>

b Text<br>

$ 0.00<br>

c Text<br>

$ 0.00<br>

d Text<br>

$ 0.00<br>

e Text<br>

$ 0.00<br>

f Text<br>

$ 0.00<br>

<br>

<br>

<br>

Total:<br>

$<input name=”tp” size=”13″ maxlength=”6″ value=”40″><br>

Money you save switching to <font color=”#0000FF”><b>Splash Plumbing!</b></font><br>

$<input type=”text” name=”ms” size=”10″ maxlength=”5″ value=”0″><input type=”button” value =”Savings” name=”Submit3″ onClick=”subit()”></form></td>

</tr></div>

</table></p>

<p>&nbsp; </p>

<p> </p>

</body>

</html> [/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@fredmvMar 27.2004 — Without looking too hard, try changing all instances of [font=courier]parseInt[/font] to [font=courier]parseFloat[/font].
Copy linkTweet thisAlerts:
@steelersfan88Mar 27.2004 — then for rounding purposes, you can use << .toFixed(2) >> to always wshow to places.

If you want less than 1000 to show only, use:[CODE]txtBox.value = "$"+ (amount < 1000) ? amount.toFixed(2) : "1000.00"[/CODE]
×

Success!

Help @lylesback2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...