/    Sign up×
Community /Pin to ProfileBookmark

how do I make my results show a decimal point

I have a javascript problem. I’m using radio buttons to hold values and based on when a user clicks on a radio button, it will add the price to a read only text box.

The problem I’m facing is trying to convert the whole number to a decimal. It started off in the database as a decimal and now when using asp to add to javascript, it displays as a whole number. How do I convert it back? I’ve tried to use the parseDouble function but it will not work, unless I’m not using it right. Here’s my code and I thank you before hand for helping:

WriteLn(“<script language=JavaScript src=/includes/functions.js></script>”)
WriteLn(“<script language=JavaScript>”)
WriteLn(“<!–“)
WriteLn(“function CalculateTotal() {“)
WriteLn(“if(document.main.subYear[0].checked && document.main.SAME_ADDRESS.value == ‘Y’) {“)
WriteLn(“document.main.TOTAL.value =” & DEFAULT1)
WriteLn(“} else if(document.main.subYear[0].checked && document.main.SAME_ADDRESS.value != ‘Y’ && document.main.SHIP_COUNTRY.value == ‘US’) {“)
WriteLn(“document.main.TOTAL.value =” & CDbl(DEFAULT1))
WriteLn(“} else if(document.main.subYear[0].checked && document.main.SAME_ADDRESS.value != ‘Y’ && document.main.SHIP_COUNTRY.value != ‘US’) {“)
WriteLn(“document.main.TOTAL.value =” & totalParam3)
WriteLn(“} else if(document.main.subYear[1].checked && document.main.SAME_ADDRESS.value == ‘Y’) {“)
WriteLn(“document.main.TOTAL.value =” & CDbl(DEFAULT2))
WriteLn(“} else if(document.main.subYear[1].checked && document.main.SAME_ADDRESS.value != ‘Y’ && document.main.SHIP_COUNTRY.value == ‘US’) {“)
WriteLn(“document.main.TOTAL.value =” & CDbl(DEFAULT2))
WriteLn(“} else if(document.main.subYear[1].checked && document.main.SAME_ADDRESS.value != ‘Y’ && document.main.SHIP_COUNTRY.value != ‘US’) {“)
WriteLn(“document.main.TOTAL.value =” & totalParam4)
WriteLn(“} else if(document.main.subYear[2].checked && document.main.SAME_ADDRESS.value == ‘Y’) {“)
WriteLn(“document.main.TOTAL.value =” & CDbl(DEFAULT3))
WriteLn(“} else if(document.main.subYear[2].checked && document.main.SAME_ADDRESS.value != ‘Y’ && document.main.SHIP_COUNTRY.value == ‘US’) {“)
WriteLn(“document.main.TOTAL.value =” & CDbl(DEFAULT3))
WriteLn(“} else if(document.main.subYear[2].checked && document.main.SAME_ADDRESS.value != ‘Y’ && document.main.SHIP_COUNTRY.value != ‘US’) {“)
WriteLn(“document.main.TOTAL.value =” & totalParam5)
WriteLn(“}}”)

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@mercury7Sep 30.2004 — Do you mean like this?
[code=php]
number=parseFloat(number);
[/code]


That should add a ".0" after an integer.
Copy linkTweet thisAlerts:
@comn8uauthorSep 30.2004 — I tried that but it didn't work. I had to stop because it was getting to late, but I started to figure it out. Basically, all I had to do is add quotes "'" for it to work and it did. I'll find out tomorrow more about it. Thanks for you reply.
Copy linkTweet thisAlerts:
@javaNoobieSep 30.2004 — <i>
</i>alert(Number("12").toFixed(1))
Not sure if toFixed() works on all browsers
×

Success!

Help @comn8u 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 5.25,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...