@@ -141,12 +141,12 @@ public static function fromFloat($fltValue, $scale = null)
141
141
if (!is_float ($ fltValue )) {
142
142
throw new InvalidArgumentTypeException (
143
143
array ('float ' ),
144
- is_object ($ fltValue ) ? get_class ($ fltValue ) : gettype ($ fltValue ),
144
+ is_object ($ fltValue ) ?
145
+ get_class ($ fltValue ) :
146
+ gettype ($ fltValue ),
145
147
'$fltValue must be of type float '
146
148
);
147
- }
148
-
149
- if ($ fltValue === INF ) {
149
+ } elseif ($ fltValue === INF ) {
150
150
return Decimal::getPositiveInfinite ();
151
151
} elseif ($ fltValue === -INF ) {
152
152
return Decimal::getNegativeInfinite ();
@@ -156,14 +156,18 @@ public static function fromFloat($fltValue, $scale = null)
156
156
);
157
157
}
158
158
159
+ $ dec_scale = $ scale === null ?
160
+ 8 :
161
+ $ scale ;
162
+
159
163
return new Decimal (
160
164
number_format (
161
165
$ fltValue ,
162
- $ scale === null ? 8 : $ scale ,
166
+ $ dec_scale ,
163
167
'. ' ,
164
168
''
165
169
),
166
- $ scale === null ? 8 : $ scale
170
+ $ dec_scale
167
171
);
168
172
}
169
173
@@ -182,9 +186,7 @@ public static function fromString($strValue, $scale = null)
182
186
is_object ($ strValue ) ? get_class ($ strValue ) : gettype ($ strValue ),
183
187
'$strVlue must be of type string. '
184
188
);
185
- }
186
-
187
- if (preg_match ('/^([+\-]?)0*(([1-9][0-9]*|[0-9])(\.[0-9]+)?)$/ ' , $ strValue , $ captures ) === 1 ) {
189
+ } elseif (preg_match ('/^([+\-]?)0*(([1-9][0-9]*|[0-9])(\.[0-9]+)?)$/ ' , $ strValue , $ captures ) === 1 ) {
188
190
189
191
// Now it's time to strip leading zeros in order to normalize inner values
190
192
$ value = self ::normalizeSign ($ captures [1 ]) . $ captures [2 ];
0 commit comments