| 12
 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
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 
 | function FormatNumber(textbox, decimalSeparator, decimalDigits, groupSeparator, groupDigits, enableGroupFormatting, currencySymbol, enableCurrencySymbol, allowNegative, negativeCss, negativeStyle)
{
   var temp = textbox.value;
 
   temp = ExtractNumber(textbox.value, decimalSeparator, decimalDigits, allowNegative);
 
   // Strip negative sign and hold the information in a boolean value
   var isNegative = temp.length > 0 && temp.charAt(0) == '-';
   temp = temp.replace('-', '');
 
   // Strip non significant zeros (ea : 000052 --> 52)
   temp = RemoveNonSignificantZeros(temp, decimalSeparator)
 
   // Apply Style Formatting
   ApplyStyleFormatting(textbox, isNegative, negativeCss, negativeStyle);
 
   // Check if it is necessary to split decimal and integer value
   if ((decimalDigits > 0) && (temp.indexOf(decimalSeparator) != -1))
   {
      // Split value into decimal and integer part
      var intPart = ent = temp.split(decimalSeparator)[0];
      var decPart = temp.split(decimalSeparator)[1];
 
      // Rebuild the whole value by joining integer, separator and decimal part
      temp = ApplyGroupSeparator(intPart, groupSeparator, groupDigits, enableGroupFormatting) + decimalSeparator + decPart;
   }
   else
   {
      temp = ApplyGroupSeparator(temp, groupSeparator, groupDigits, enableGroupFormatting);
   }
 
   // Add the negative sign if needed
   if (allowNegative && isNegative)
   {
      // only added if value is not empty
      temp = "-" + temp;
   }
 
   // Add the currency symbol if needed
   if (enableCurrencySymbol)
   {
      // only added if value is not empty
      temp = (temp == "") ? temp : currencySymbol + " " + temp;
   }
 
   textbox.value = temp;	
} | 
Partager