|
|
|
|
 |
|  |
 |
Hamelin |
| Arrotondare con Javascript |
27-04-2005 14:08 |
|
 |
Hamelin |
.pifferaio.magico.

Registered: Feb 2003
Posts: 662 (0.08 al dì)
Location: ..tra i monti intorno ad Hamelin..
Corso: Ingegneria Informatica
Anno: 3°
Time Online: 7 Days, 7:19:55 [...]
Status: Offline
Edit | Report | IP: Logged |
Arrotondare con Javascript
Domanda: per arrotondare un numero all'intero più vicino Javascript mette a disposizione la funzione Math.round ()
Ma se volessi arrotondare un numero decimale a un numero con n cifre dopo la virgola? (chiedo se esiste una funzione apposta... o se devo procedere altrimenti)
__________________
Bjarne Stroustrup: "I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone."
Andrew S. Tanenbaum: "Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway."
Edsger Dijkstra: "Computer Science is no more about computers than astronomy is about telescopes."
Robert Firth: "One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs."
Donald Knuth: "A mathematical formula should never be 'owned' by anybody! Mathematics belong to God."
|
|
27-04-2005 14:08 |
|
|
|  |
 |
ripe |
| Hai ragione, c'è un modo per farlo con il metodo ... |
27-04-2005 14:37 |
|
 |
ripe |
- up in the mountains -

Registered: Jun 2002
Posts: 9469 (1.10 al dì)
Location: Cinisellooo
Corso: TICO TICO
Anno: Primo
Time Online: 61 Days, 2:33:39 [...]
Status: Offline
Edit | Report | IP: Logged |
Hai ragione, c'è un modo per farlo con il metodo round, ma non è proprio il massimo dell'eleganza...
Ad esempio, per arrotondare il numero 15,456 ad una sola cifra decimale puoi fare:
n = Math.round(15,456 * 10) / 10
Così con la moltiplicazione sposti la virgola a destra e arrotondi con il round tutto il resto, mentre con la divisione riporti la virgola a sinistra al posto giusto e ottieni il risultato desiderato.
Cambiando il fattore di moltiplicazione o divisione ottieni le altre possibilità! 
__________________
«And if you ever smell christian blood up in the mountains, then get your axe and chop them down!»
|
|
27-04-2005 14:37 |
|
|
|  |
 |
Hamelin |
| Ok. Era quello a cui avevo pensato. Quindi mi conf ... |
27-04-2005 14:45 |
|
 |
Hamelin |
.pifferaio.magico.

Registered: Feb 2003
Posts: 662 (0.08 al dì)
Location: ..tra i monti intorno ad Hamelin..
Corso: Ingegneria Informatica
Anno: 3°
Time Online: 7 Days, 7:19:55 [...]
Status: Offline
Edit | Report | IP: Logged |
Ok. Era quello a cui avevo pensato. Quindi mi confermi che non c'è alcuna funzione predefinita?
__________________
Bjarne Stroustrup: "I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone."
Andrew S. Tanenbaum: "Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway."
Edsger Dijkstra: "Computer Science is no more about computers than astronomy is about telescopes."
Robert Firth: "One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs."
Donald Knuth: "A mathematical formula should never be 'owned' by anybody! Mathematics belong to God."
|
|
27-04-2005 14:45 |
|
|
|  |
 |
ripe |
| Io ho usato sempre quel modo, non conosco altri me ... |
27-04-2005 14:46 |
|
 |
ripe |
- up in the mountains -

Registered: Jun 2002
Posts: 9469 (1.10 al dì)
Location: Cinisellooo
Corso: TICO TICO
Anno: Primo
Time Online: 61 Days, 2:33:39 [...]
Status: Offline
Edit | Report | IP: Logged |
Io ho usato sempre quel modo, non conosco altri metodi... 
__________________
«And if you ever smell christian blood up in the mountains, then get your axe and chop them down!»
|
|
27-04-2005 14:46 |
|
|
|  |
 |
Hamelin |
| Un altro quesito: il campo innerText di un oggetto ... |
28-04-2005 19:12 |
|
 |
Hamelin |
.pifferaio.magico.

Registered: Feb 2003
Posts: 662 (0.08 al dì)
Location: ..tra i monti intorno ad Hamelin..
Corso: Ingegneria Informatica
Anno: 3°
Time Online: 7 Days, 7:19:55 [...]
Status: Offline
Edit | Report | IP: Logged |
Un altro quesito: il campo innerText di un oggetto dell'HTML DOM funziona solo per MS Internet Explorer... non c'è un metodo standard per modificare il contenuto di un elemento HTML (quello che sta tra i due tag)?
Grazie ancora!
__________________
Bjarne Stroustrup: "I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone."
Andrew S. Tanenbaum: "Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway."
Edsger Dijkstra: "Computer Science is no more about computers than astronomy is about telescopes."
Robert Firth: "One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs."
Donald Knuth: "A mathematical formula should never be 'owned' by anybody! Mathematics belong to God."
|
|
28-04-2005 19:12 |
|
|
|  |
 |
ripe |
| Uhm... non mi sono mai posto il problema... [b]inn ... |
28-04-2005 19:27 |
|
 |
ripe |
- up in the mountains -

Registered: Jun 2002
Posts: 9469 (1.10 al dì)
Location: Cinisellooo
Corso: TICO TICO
Anno: Primo
Time Online: 61 Days, 2:33:39 [...]
Status: Offline
Edit | Report | IP: Logged |
Uhm... non mi sono mai posto il problema... innerHTML con solo il testo specificato non funziona? Altrimenti puoi provare un nodeValue...
Anche se non è standard, preferisco il modello DOM di Internet Explorer... 
__________________
«And if you ever smell christian blood up in the mountains, then get your axe and chop them down!»
|
|
28-04-2005 19:27 |
|
|
|  |
 |
Hamelin |
| Mah... sì... in fondo non è nemmeno molto utile. ... |
29-04-2005 17:30 |
|
 |
Hamelin |
.pifferaio.magico.

Registered: Feb 2003
Posts: 662 (0.08 al dì)
Location: ..tra i monti intorno ad Hamelin..
Corso: Ingegneria Informatica
Anno: 3°
Time Online: 7 Days, 7:19:55 [...]
Status: Offline
Edit | Report | IP: Logged |
Mah... sì... in fondo non è nemmeno molto utile...
__________________
Bjarne Stroustrup: "I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone."
Andrew S. Tanenbaum: "Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway."
Edsger Dijkstra: "Computer Science is no more about computers than astronomy is about telescopes."
Robert Firth: "One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs."
Donald Knuth: "A mathematical formula should never be 'owned' by anybody! Mathematics belong to God."
|
|
29-04-2005 17:30 |
|
|
|  |
 |
Hamelin |
| Curiosità... |
01-05-2005 19:17 |
|
 |
Hamelin |
.pifferaio.magico.

Registered: Feb 2003
Posts: 662 (0.08 al dì)
Location: ..tra i monti intorno ad Hamelin..
Corso: Ingegneria Informatica
Anno: 3°
Time Online: 7 Days, 7:19:55 [...]
Status: Offline
Edit | Report | IP: Logged |
Curiosità...
Perché usando il metodo navigator.appCodeName ottengo 'Mozilla' per Internet Explorer?
__________________
Bjarne Stroustrup: "I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone."
Andrew S. Tanenbaum: "Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway."
Edsger Dijkstra: "Computer Science is no more about computers than astronomy is about telescopes."
Robert Firth: "One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs."
Donald Knuth: "A mathematical formula should never be 'owned' by anybody! Mathematics belong to God."
|
|
01-05-2005 19:17 |
|
|
|  |
 |
ripe |
| Perchè IE si registra in questa classe di browser ... |
01-05-2005 22:36 |
|
 |
ripe |
- up in the mountains -

Registered: Jun 2002
Posts: 9469 (1.10 al dì)
Location: Cinisellooo
Corso: TICO TICO
Anno: Primo
Time Online: 61 Days, 2:33:39 [...]
Status: Offline
Edit | Report | IP: Logged |
Perchè IE si registra in questa classe di browser... anche Asp.Net restituisce questo valore:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
__________________
«And if you ever smell christian blood up in the mountains, then get your axe and chop them down!»
|
|
01-05-2005 22:36 |
|
|
|  |
 |
Hamelin |
| Giochino in JS |
19-05-2005 09:43 |
|
 |
Hamelin |
.pifferaio.magico.

Registered: Feb 2003
Posts: 662 (0.08 al dì)
Location: ..tra i monti intorno ad Hamelin..
Corso: Ingegneria Informatica
Anno: 3°
Time Online: 7 Days, 7:19:55 [...]
Status: Offline
Edit | Report | IP: Logged |
Giochino in JS
C'è la possibilità di nascondere in qualche modo il sorgente di un programmino scritto in Javascript?
...è che ho fatto un piccolo quiz... e non vorrei che le risposte siano visibili a tutti... se può ffa?
__________________
Bjarne Stroustrup: "I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone."
Andrew S. Tanenbaum: "Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway."
Edsger Dijkstra: "Computer Science is no more about computers than astronomy is about telescopes."
Robert Firth: "One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs."
Donald Knuth: "A mathematical formula should never be 'owned' by anybody! Mathematics belong to God."
|
|
19-05-2005 09:43 |
|
|
|  |
 |
ripe |
| Prova con un obfuscator, ne troverai anche qualcun ... |
19-05-2005 09:53 |
|
 |
ripe |
- up in the mountains -

Registered: Jun 2002
Posts: 9469 (1.10 al dì)
Location: Cinisellooo
Corso: TICO TICO
Anno: Primo
Time Online: 61 Days, 2:33:39 [...]
Status: Offline
Edit | Report | IP: Logged |
Prova con un obfuscator, ne troverai anche qualcuno gratis! 
__________________
«And if you ever smell christian blood up in the mountains, then get your axe and chop them down!»
|
|
19-05-2005 09:53 |
|
|
|  |
 |
| All times are GMT. The time now is 12:14. |
|
|
 |
|
 |
|
|
|  |
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
|
|
|
|
|
|