@@ -37,7 +37,6 @@ export default function(locale) {
37
37
// Is this an integer type?
38
38
// Can this type generate exponential notation?
39
39
var formatType = formatTypes [ type ] ,
40
- integer = / [ b c d o x X ] / . test ( type ) ,
41
40
maybeSuffix = ! type || / [ d e f g p r s % ] / . test ( type ) ;
42
41
43
42
// Set the default precision if not specified,
@@ -49,31 +48,36 @@ export default function(locale) {
49
48
: Math . max ( 0 , Math . min ( 20 , precision ) ) ;
50
49
51
50
return function ( value ) {
52
- value = + value ;
53
-
54
- // Return the empty string for floats formatted as ints.
55
- if ( integer && ( value % 1 ) ) return "" ;
56
-
57
- // Convert negative to positive, and compute the prefix.
58
- // Note that -0 is not less than 0, but 1 / -0 is!
59
- var valueNegative = ( value < 0 || 1 / value < 0 ) && ( value *= - 1 , true ) ,
60
- valuePrefix = ( valueNegative ? ( sign === "(" ? sign : "-" ) : sign === "-" || sign === "(" ? "" : sign ) + prefix ;
61
-
62
- // Perform the initial formatting.
63
- value = formatType ( value , precision ) ;
64
-
65
- // Compute the suffix.
66
- var valueSuffix = suffix + ( type === "s" ? prefixes [ 8 + prefixExponent / 3 ] : "" ) + ( valueNegative && sign === "(" ? ")" : "" ) ;
67
-
68
- // Break the formatted value into the integer “value” part that can be
69
- // grouped, and fractional or exponential “suffix” part that is not.
70
- if ( maybeSuffix ) {
71
- var i = - 1 , n = value . length , c ;
72
- while ( ++ i < n ) {
73
- if ( c = value . charCodeAt ( i ) , 48 > c || c > 57 ) {
74
- valueSuffix = ( c === 46 ? decimal + value . slice ( i + 1 ) : value . slice ( i ) ) + valueSuffix ;
75
- value = value . slice ( 0 , i ) ;
76
- break ;
51
+ var valuePrefix = prefix ,
52
+ valueSuffix = suffix ;
53
+
54
+ if ( type === "c" ) {
55
+ valueSuffix = formatType ( value ) + valueSuffix ;
56
+ value = "" ;
57
+ } else {
58
+ value = + value ;
59
+
60
+ // Convert negative to positive, and compute the prefix.
61
+ // Note that -0 is not less than 0, but 1 / -0 is!
62
+ var valueNegative = ( value < 0 || 1 / value < 0 ) && ( value *= - 1 , true ) ;
63
+
64
+ // Perform the initial formatting.
65
+ value = formatType ( value , precision ) ;
66
+
67
+ // Compute the prefix and suffix.
68
+ valuePrefix = ( valueNegative ? ( sign === "(" ? sign : "-" ) : sign === "-" || sign === "(" ? "" : sign ) + valuePrefix ;
69
+ valueSuffix = valueSuffix + ( type === "s" ? prefixes [ 8 + prefixExponent / 3 ] : "" ) + ( valueNegative && sign === "(" ? ")" : "" ) ;
70
+
71
+ // Break the formatted value into the integer “value” part that can be
72
+ // grouped, and fractional or exponential “suffix” part that is not.
73
+ if ( maybeSuffix ) {
74
+ var i = - 1 , n = value . length , c ;
75
+ while ( ++ i < n ) {
76
+ if ( c = value . charCodeAt ( i ) , 48 > c || c > 57 ) {
77
+ valueSuffix = ( c === 46 ? decimal + value . slice ( i + 1 ) : value . slice ( i ) ) + valueSuffix ;
78
+ value = value . slice ( 0 , i ) ;
79
+ break ;
80
+ }
77
81
}
78
82
}
79
83
}
0 commit comments