Dateigrösse: 7.17 kb
1 2 <style> 3 h2 { font-family:palatino,calibri,verdana,sans-serif; font-weight:bolder; font-size:20pt !important; margin:0; padding:0 0 0.8em 0; color: #333; letter-spacing: 0.1em; } 4 .content form { font: 11pt verdana,sans-serif !important; padding:1pt 0; } 5 .content p { padding:5px 0 !important; margin-bottom:1pt; } 6 .result, .raw, .runden { font: 11pt verdana,sans-serif !important; } 7 .result { min-width: 165pt !important; font-size:11pt !important; font-weight:bold !important; padding:8px 4px 8px 8px !important; border:1px solid gray; border-radius:3pt; box-shadow:2pt 2pt 3pt crimson; } 8 .raw { width: 175pt !important; border-radius:3pt; padding:5pt 5pt !important; } 9 .runden { width: 175pt !important; } 10 .interg { margin-top:2em !important; padding:5pt 5pt !important; } 11 12 .result .weiter { float:right; } 13 .result .weiter a { font-weight:bold; text-decoration:none; color:#000; padding:0 10px 0 20px; } 14 .result .weiter a:hover { text-decoration:overline; color:crimson; } 15 </style> 16 17 <script> 18 function round(wert, dez) 19 { 20 wert = parseFloat(wert); 21 if (!wert) return 0; 22 23 dez = parseInt(dez); 24 if (!dez) dez=0; 25 26 var umrechnungsfaktor = Math.pow(10, dez); 27 var multi = Math.round(wert * umrechnungsfaktor); 28 var res = multi / umrechnungsfaktor; 29 /*** Control in der Console ***/ 30 console.log('###################################'); 31 console.log(umrechnungsfaktor); 32 console.log(multi); 33 console.log(dez); 34 console.log("Resultat: " + res); 35 if(umrechnungsfaktor == '0.00001') { 36 res = Math.round(res); 37 console.log("Resultat_r: " + res); 38 } 39 if (typeof res === 'number') { 40 text = res.toString(); 41 } 42 const myArray = text.split("."); 43 if(myArray[1]==000000001 && dez<1) { 44 console.log("Resultat_GZ: " + myArray[1]); 45 res = parseInt(myArray[0]); 46 } 47 console.log('Stellen: '+myArray[0].length); 48 console.log((res).toLocaleString('de-ch')); 49 if(myArray[0].length >3 && dez<4) { 50 return (res).toLocaleString('de-ch'); 51 } else { 52 return res; 53 } 54 } 55 /*** Beispiel **************************************************** 56 zahl = 8175.4647693075; 57 gerundet = round(zahl, 3); //auf drei Stellen runden = 8175.465 58 *****************************************************************/ 59 function fuckme (wert, dez=8) 60 { 61 valeur = wert.replace(',', '.'); 62 valore = valeur.replace(/'/g, ''); 63 console.log(valore); 64 65 index(valore); 66 67 var result = 0; 68 result = round(valore, dez); 69 console.log("Resultat_final: " + result); 70 71 var weiter = '<div class="weiter"><a href="./?nid=eight" title="nächste Zahl">»»»</a></div>'; 72 73 if(valore!=result) { 74 document.getElementById('resultbox').innerHTML=result; 75 document.getElementById('resultbox').innerHTML+=weiter; 76 hideres(wert, dez); 77 } 78 79 } 80 81 function index(valore) 82 { 83 var l = valore.length; // alle Dezimalstellen (plus Kommata/Punkt) 84 var n = valore.indexOf("."); // Position Komma/Punkt, wenn keiner n = -1 85 var k = ((l-n)-2); // Differenz von l und n minus Punkt und letzter Stelle (-2) 86 87 //numinfo(l,n,k); 88 89 error(n,l); 90 91 if(n != -1) 92 { 93 while(k >0) { 94 console.log(k); 95 document.getElementById(k).style.display='flex'; 96 k--; 97 } 98 n--; 99 while(n >=0) { 100 console.log(n); 101 document.getElementById('p'+n).style.display='flex'; 102 n--; 103 } 104 } else { 105 l--; 106 while(l >=0) { 107 console.log(l); 108 document.getElementById('p'+l).style.display='flex'; 109 l--; 110 } 111 } 112 } 113 function error(n, l) { 114 if((n == -1 && l >7) || (n != -1 && n >7)) { 115 errormsg(); 116 } 117 if(((l-n)-1) >7) { 118 errormsg2(); 119 } 120 } 121 function errormsg() { 122 document.write('<html style="padding:0; margin:0;"><body style="padding:2.5em 3em;"><h1 style="font:bold 20pt verdana,sans-serif; color:crimson;">♣ Zahl zu gross ♦ max. 9 Millionen ♠</h1><button style="padding:5pt 10pt; margin-top:1em; border-radius:5px; font:bold 11pt verdana,sans-serif; border:2pt solid black; background:white;" onclick="location.href=\'http://www.michaelster.ch/lernen/?nid=eight\';">verstanden</button></body></html>'); 123 } 124 function errormsg2() { 125 document.write('<html style="padding:0; margin:0;"><body style="padding:2.5em 3em;"><h1 style="font:bold 20pt verdana,sans-serif; color:crimson;">♦ Zu lange Zahl ♣ max. 7 Dezimalstellen ♠</h1><button style="padding:5pt 10pt; margin-top:1em; border-radius:5px; font:bold 11pt verdana,sans-serif; border:2pt solid black; background:white;" onclick="location.href=\'http://www.michaelster.ch/lernen/?nid=eight\';">verstanden</button></body></html>'); 126 } 127 function numinfo(l,n,k) { 128 document.getElementById("interg").innerHTML = n + " :: " + l + " :: " + k; 129 } 130 function hideres(wert, dez, valore) { 131 if(wert && dez) { 132 document.getElementById('interg').style.display='flex'; 133 document.getElementById('resultbox').style.display='inline-block'; 134 } else { 135 document.getElementById('interg').style.display='none'; 136 document.getElementById('resultbox').style.display='none'; 137 } 138 } 139 140 </script> 141 142 143 <h2>Math.round()</h2> 144 145 <div class="content"> 146 <form name="f0" id="f0"> 147 <p>Zahl:</p> 148 <input type="text" id="zahl" name="rawnumber" placeholder="Bitte hier eingeben" onblur="fuckme(this.value);" title="Kein Komma, nur Punkt" size="15" maxlength="15" class="raw" value="" autofocus /> 149 <br><br> 150 <p>runden auf:</p> 151 <select name="selround" class="runden" size="1" id="sel_id" onchange="fuckme(document.getElementById('f0').elements['rawnumber'].value, this.value);"> 152 <option value="">Bitte wählen </option> 153 <option value="">- <> - <> - <> - <> - <> - <> - <> - </option> 154 <option style="display:none" id="6" value="6"> • millionstel</option> 155 <option style="display:none" id="5" value="5"> • hunderttausendstel</option> 156 <option style="display:none" id="4" value="4"> • zehntausendstel</option> 157 <option style="display:none" id="3" value="3"> • tausendstel</option> 158 <option style="display:none" id="2" value="2"> • hundertstel</option> 159 <option style="display:none" id="1" value="1"> • zehntel</option> 160 <option style="display:none" id="p0" value="0"> ¤ Einer</option> 161 <option style="display:none" id="p1" value="-1"> ¤ Zehner</option> 162 <option style="display:none" id="p2" value="-2"> ¤ Hunderter</option> 163 <option style="display:none" id="p3" value="-3"> ¤ Tausender</option> 164 <option style="display:none" id="p4" value="-4"> ¤ Zehntausender</option> 165 <option style="display:none" id="p5" value="-5"> ¤ Hunderttausender</option> 166 <option style="display:none" id="p6" value="-6"> ¤ Millionen</option> 167 <option> </option> 168 </select> 169 <p style="display:none" id="interg" class="interg"> 170 <b>Resultat:</b> 171 </p> 172 <div style="display:none" class="result" id="resultbox"><div class="weiter"> <a href="./?nid=eight" title="nächste Zahl">»»»</a></div></div> 173 </form> 174 </div> 175