visto che sto diventando scemo mando pure la mia soluzione.
c'è pure quella di fcaldera che conservo nella mia libreria![]()
codice:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>a</title> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"> <meta name="ProgId" content="VisualStudio.HTML"> <meta name="Originator" content="Microsoft Visual Studio .NET 7.1"> <script id="clientEventHandlersJS" language="javascript"> <!-- function Button1_onclick() { var valore, decimale, intero, numero_migliaia, i, resto, numero_formattato, tmp; valore = document.getElementById("Text1").value; decimale = valore.substring(valore.length, valore.length - 2); document.getElementById("Text2").value = "," + decimale; intero = valore.substring(0, valore.length - 2); document.getElementById("Text2").value = intero + "," + decimale; numero_migliaia = Math.floor((intero.length - 1) / 3); numero_formattato = ""; resto = intero; for(i = 0; i < numero_migliaia; i++) { tmp = resto.substring(resto.length, resto.length - 3); resto = resto.substring(0, resto.length - 3); numero_formattato = "." + tmp + numero_formattato; } numero_formattato = resto + numero_formattato; if(numero_formattato == "" ) numero_formattato = "0"; if(decimale == "" ) decimale = "0"; if(decimale.length < 2) decimale = "0" + decimale; numero_formattato = numero_formattato + "," + decimale ; document.getElementById("Text2").value = (numero_formattato); document.getElementById("Text3").value = format(valore); } function format(number) { number = String(number); formatted = number.replace(/\d*?(\d{2})$/, ",$1"); number = number.replace(/(\d*?)(\d{2})$/, "$1"); while (number.length > 3) { formatted = number.replace(/\d*?(\d{3})$/, ".$1") + formatted; number = number.replace(/(\d*?)\d{3}$/, "$1"); } formatted = number + formatted; return formatted; } //--> </script> </head> <body MS_POSITIONING="FlowLayout"> <INPUT type="text" ID="Text1" NAME="Text1" style="border:1px black solid;TEXT-ALIGN: center;" value="1356089415"> <INPUT type="button" value="Converti" ID="Button1" NAME="Button1" language="javascript" onclick="return Button1_onclick()"> <INPUT type="text" ID="Text2" NAME="Text2" style="border:1px black solid;TEXT-ALIGN: center;"> <INPUT type="text" ID="Text3" NAME="Text3" style="border:1px black solid;TEXT-ALIGN: center;"> </body> </html>

Rispondi quotando