fix rounding from string
This commit is contained in:
parent
b97a4ae031
commit
f94b7aadd3
@ -78,6 +78,16 @@ class MoneyToLocalizedStringTransformerTest extends TestCase
|
|||||||
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
|
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
|
||||||
IntlTestHelper::requireFullIntl($this, false);
|
IntlTestHelper::requireFullIntl($this, false);
|
||||||
\Locale::setDefault('de_AT');
|
\Locale::setDefault('de_AT');
|
||||||
|
|
||||||
$this->assertSame(3655, (int) $transformer->reverseTransform('36,55'));
|
$this->assertSame(3655, (int) $transformer->reverseTransform('36,55'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFloatToIntConversionMismatchOnTransform()
|
||||||
|
{
|
||||||
|
$transformer = new MoneyToLocalizedStringTransformer(null, null, MoneyToLocalizedStringTransformer::ROUND_DOWN, 100);
|
||||||
|
IntlTestHelper::requireFullIntl($this, false);
|
||||||
|
\Locale::setDefault('de_AT');
|
||||||
|
|
||||||
|
$this->assertSame('10,20', $transformer->transform(1020));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -708,6 +708,7 @@ class NumberFormatter
|
|||||||
} elseif (isset(self::$customRoundingList[$roundingModeAttribute])) {
|
} elseif (isset(self::$customRoundingList[$roundingModeAttribute])) {
|
||||||
$roundingCoef = pow(10, $precision);
|
$roundingCoef = pow(10, $precision);
|
||||||
$value *= $roundingCoef;
|
$value *= $roundingCoef;
|
||||||
|
$value = (float) (string) $value;
|
||||||
|
|
||||||
switch ($roundingModeAttribute) {
|
switch ($roundingModeAttribute) {
|
||||||
case self::ROUND_CEILING:
|
case self::ROUND_CEILING:
|
||||||
|
@ -428,6 +428,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
|
|||||||
// array(1.125, '1.13'),
|
// array(1.125, '1.13'),
|
||||||
array(1.127, '1.13'),
|
array(1.127, '1.13'),
|
||||||
array(1.129, '1.13'),
|
array(1.129, '1.13'),
|
||||||
|
array(1020 / 100, '10.20'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,6 +452,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
|
|||||||
array(1.125, '1.12'),
|
array(1.125, '1.12'),
|
||||||
array(1.127, '1.13'),
|
array(1.127, '1.13'),
|
||||||
array(1.129, '1.13'),
|
array(1.129, '1.13'),
|
||||||
|
array(1020 / 100, '10.20'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,6 +476,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
|
|||||||
array(1.125, '1.12'),
|
array(1.125, '1.12'),
|
||||||
array(1.127, '1.13'),
|
array(1.127, '1.13'),
|
||||||
array(1.129, '1.13'),
|
array(1.129, '1.13'),
|
||||||
|
array(1020 / 100, '10.20'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -498,6 +501,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
|
|||||||
array(-1.123, '-1.12'),
|
array(-1.123, '-1.12'),
|
||||||
array(-1.125, '-1.12'),
|
array(-1.125, '-1.12'),
|
||||||
array(-1.127, '-1.12'),
|
array(-1.127, '-1.12'),
|
||||||
|
array(1020 / 100, '10.20'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,6 +526,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
|
|||||||
array(-1.123, '-1.13'),
|
array(-1.123, '-1.13'),
|
||||||
array(-1.125, '-1.13'),
|
array(-1.125, '-1.13'),
|
||||||
array(-1.127, '-1.13'),
|
array(-1.127, '-1.13'),
|
||||||
|
array(1020 / 100, '10.20'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,6 +551,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
|
|||||||
array(-1.123, '-1.12'),
|
array(-1.123, '-1.12'),
|
||||||
array(-1.125, '-1.12'),
|
array(-1.125, '-1.12'),
|
||||||
array(-1.127, '-1.12'),
|
array(-1.127, '-1.12'),
|
||||||
|
array(1020 / 100, '10.20'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,6 +576,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
|
|||||||
array(-1.123, '-1.13'),
|
array(-1.123, '-1.13'),
|
||||||
array(-1.125, '-1.13'),
|
array(-1.125, '-1.13'),
|
||||||
array(-1.127, '-1.13'),
|
array(-1.127, '-1.13'),
|
||||||
|
array(1020 / 100, '10.20'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user