NumberFormat.as 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package {
  2. import object_helper;
  3. public class NumberFormat
  4. {
  5. public static var DEFAULT_NUM_DECIMALS:Number = 2;
  6. public var numDecimals:Number = DEFAULT_NUM_DECIMALS;
  7. public var isFixedNumDecimalsForced:Boolean = false;
  8. public var isDecimalSeparatorComma:Boolean = false;
  9. public var isThousandSeparatorDisabled:Boolean = false;
  10. public function NumberFormat( numDecimals:Number, isFixedNumDecimalsForced:Boolean, isDecimalSeparatorComma:Boolean, isThousandSeparatorDisabled:Boolean )
  11. {
  12. this.numDecimals = Parser.getNumberValue (numDecimals, DEFAULT_NUM_DECIMALS, true, false);
  13. this.isFixedNumDecimalsForced = Parser.getBooleanValue(isFixedNumDecimalsForced,false);
  14. this.isDecimalSeparatorComma = Parser.getBooleanValue(isDecimalSeparatorComma,false);
  15. this.isThousandSeparatorDisabled = Parser.getBooleanValue(isThousandSeparatorDisabled,false);
  16. }
  17. //singleton
  18. // public static function getInstance (lv,c:Number):NumberFormat{
  19. // if (c==2){
  20. // return NumberFormat.getInstanceY2(lv);
  21. // } else {
  22. // return NumberFormat.getInstance(lv);
  23. // }
  24. // }
  25. private static var _instance:NumberFormat = null;
  26. public static function getInstance( json:Object ):NumberFormat {
  27. if (_instance == null) {
  28. // if (lv==undefined || lv == null){
  29. // lv=_root.lv;
  30. // }
  31. var o:Object = {
  32. num_decimals: 2,
  33. is_fixed_num_decimals_forced: 0,
  34. is_decimal_separator_comma: 0,
  35. is_thousand_separator_disabled: 0
  36. };
  37. object_helper.merge_2( json, o );
  38. _instance = new NumberFormat (
  39. o.num_decimals,
  40. o.is_fixed_num_decimals_forced==1,
  41. o.is_decimal_separator_comma==1,
  42. o.is_thousand_separator_disabled==1
  43. );
  44. // trace ("getInstance NEW!!!!");
  45. // trace (_instance.numDecimals);
  46. // trace (_instance.isFixedNumDecimalsForced);
  47. // trace (_instance.isDecimalSeparatorComma);
  48. // trace (_instance.isThousandSeparatorDisabled);
  49. } else {
  50. //trace ("getInstance found");
  51. }
  52. return _instance;
  53. }
  54. private static var _instanceY2:NumberFormat = null;
  55. public static function getInstanceY2( json:Object ):NumberFormat{
  56. if (_instanceY2 == null) {
  57. // if (lv==undefined || lv == null){
  58. // lv=_root.lv;
  59. // }
  60. var o:Object = {
  61. num_decimals: 2,
  62. is_fixed_num_decimals_forced: 0,
  63. is_decimal_separator_comma: 0,
  64. is_thousand_separator_disabled: 0
  65. };
  66. object_helper.merge_2( json, o );
  67. _instanceY2 = new NumberFormat (
  68. o.num_decimals,
  69. o.is_fixed_num_decimals_forced==1,
  70. o.is_decimal_separator_comma==1,
  71. o.is_thousand_separator_disabled==1
  72. );
  73. //trace ("getInstanceY2 NEW!!!!");
  74. } else {
  75. //trace ("getInstanceY2 found");
  76. }
  77. return _instanceY2;
  78. }
  79. }
  80. }