Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Conversation

@PetrHeinz
Copy link

@PetrHeinz PetrHeinz commented Feb 14, 2019

Hello, I've experienced some strange behavior of Decimal::fromFloat() when lowering the scale using the second parameter. I've provided additional tests and fixed the behavior using innerRound so it's consistent with Decimal::fromString().

Even though the last commit in this repo was created quite a while ago, I hope we can get it merged and released. Let me know if there's anything I can do to ease the merge process 🙂

The console output of the added tests with the current behavior describing the issue:

1) DecimalFromFloatTest::testFromFloat with data set #6 (1.000001, '1.00', 2)
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'1.00'
+'1.000001'

2) DecimalFromFloatTest::testFromFloat with data set #7 (-1.000001, '-1.00', 2)
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'-1.00'
+'-1.000001'

3) DecimalFromFloatTest::testFromFloat with data set #8 (0, '0', 0)
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'0'
+'0.'

4) DecimalFromFloatTest::testFromFloat with data set #11 (0.5, '1', 0)
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'1'
+'0.5'

5) DecimalFromFloatTest::testFromFloat with data set #12 (0.05, '0.1', 1)
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'0.1'
+'0.05'

6) DecimalFromFloatTest::testFromFloat with data set #13 (0.005, '0.01', 2)
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'0.01'
+'0.005'

7) DecimalFromFloatTest::testFromFloat with data set #14 (-0.5, '-1', 0)
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'-1'
+'-0.5'

8) DecimalFromFloatTest::testFromFloat with data set #15 (-0.05, '-0.1', 1)
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'-0.1'
+'-0.05'

9) DecimalFromFloatTest::testFromFloat with data set #16 (-0.005, '-0.01', 2)
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'-0.01'
+'-0.005'

- when created with a lower scale, innerRound is used (consistent with Decimal::fromString())
- covered by additional unit tests which fail without the code changes
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant