[JavaScript] Double wordt int.

Pagina: 1
Acties:
  • 115 views sinds 30-01-2008
  • Reageer

  • Nazgul
  • Registratie: Februari 2000
  • Laatst online: 11-10-2022

Nazgul

Digital Pizza Crew

Topicstarter
Ik heb onderstaand stukje code:
code:
1
2
3
var annulering=0.00;
annulering=annulering+1.00;
alert(annulering);

Als dit uitgevoerd wordt, krijg ik een boxje met de waarde 1 ipv 1.00
Weet iemand hoe ik wel die 1.00 kan krijgen?

No trees were killed in the sending of this message. However a large number of electrons were terribly inconvenienced.


  • BtM909
  • Registratie: Juni 2000
  • Niet online

BtM909

Watch out Guys...

Is iets wat standaard in JavaScript gebakken is! Ik heb wel een stukje code die er 2 cijfers achter de komma plaatst, maar die moet ik ff opzoeken!

Gebruik je altijd 2 cijfers achter de komma?

Ace of Base vs Charli XCX - All That She Boom Claps (RMT) | Clean Bandit vs Galantis - I'd Rather Be You (RMT)
You've moved up on my notch-list. You have 1 notch
I have a black belt in Kung Flu.


  • McVirusS
  • Registratie: Januari 2000
  • Laatst online: 15-09 16:29
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<HTML>
<HEAD>
<TITLE>Number Formatting</TITLE>
<SCRIPT LANGUAGE="JavaScript">
// generic positive number decimal formatting function
function format (expr, decplaces) {
    // raise incoming value by power of 10 times the
    // number of decimal places; round to an integer; convert to string
    var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces))
    // pad small value strings with zeros to the left of rounded number
    while (str.length <= decplaces) {
        str = "0" + str
    }
    // establish location of decimal point
    var decpoint = str.length - decplaces
    // assemble final result from: (a) the string up to the position of
    // the decimal point; (b) the decimal point; and (c) the balance
    // of the string. Return finished product.
    return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}
// turn incoming expression into a dollar value
function dollarize (expr) {
    return "$" + format(expr,2)
}
</SCRIPT>
</HEAD>
<BODY>
<H1>How to Make Money</H1>
<FORM>
Enter a positive floating point value or arithmetic expression to be converted to a currency format:<P>
<INPUT TYPE="text" NAME="entry" VALUE="1/3">
<INPUT TYPE="button" VALUE=">Dollars and Cents>" onClick="this.form.result.value=dollarize(this.form.entry.value)">
<INPUT TYPE="text" NAME="result">
</FORM>
</BODY>
</HTML>

Eerlijk gejat, je moet alleen even die dollarize function eruit slopen. (ik had geen zin om zelf script te bouwen).

  • Nazgul
  • Registratie: Februari 2000
  • Laatst online: 11-10-2022

Nazgul

Digital Pizza Crew

Topicstarter
Ik gebruik 1 of meer cijfers achter de komma.
(Tenminste dat is de bedoeling ;))

No trees were killed in the sending of this message. However a large number of electrons were terribly inconvenienced.


  • BtM909
  • Registratie: Juni 2000
  • Niet online

BtM909

Watch out Guys...

Bovenstaand script had ik ook, maar ik moest het iets anders gebruiken, dus heb ik het herschreven in 7 regels (8>

Ace of Base vs Charli XCX - All That She Boom Claps (RMT) | Clean Bandit vs Galantis - I'd Rather Be You (RMT)
You've moved up on my notch-list. You have 1 notch
I have a black belt in Kung Flu.


  • McVirusS
  • Registratie: Januari 2000
  • Laatst online: 15-09 16:29
Op dinsdag 18 september 2001 13:07 schreef BtM909 het volgende:
Bovenstaand script had ik ook, maar ik moest het iets anders gebruiken, dus heb ik het herschreven in 7 regels (8>
De echte functie is maar 6 regels........hele prestatie dat jij het dan in 7 regels doet :P.

  • Nazgul
  • Registratie: Februari 2000
  • Laatst online: 11-10-2022

Nazgul

Digital Pizza Crew

Topicstarter
Werkt.... Bedankt. :)

No trees were killed in the sending of this message. However a large number of electrons were terribly inconvenienced.


  • BtM909
  • Registratie: Juni 2000
  • Niet online

BtM909

Watch out Guys...

Op dinsdag 18 september 2001 13:10 schreef McVirusS het volgende:

De echte functie is maar 6 regels........hele prestatie dat jij het dan in 7 regels doet :P.
Touché, maar ik heb andere functionaliteit erin gebakken! ;)

Ace of Base vs Charli XCX - All That She Boom Claps (RMT) | Clean Bandit vs Galantis - I'd Rather Be You (RMT)
You've moved up on my notch-list. You have 1 notch
I have a black belt in Kung Flu.

Pagina: 1