jonathanpmartins / v-money3

Vue3 currency input/directive mask
MIT License
103 stars 27 forks source link

Opt to avoid round precision #45

Closed sougiovn closed 3 years ago

sougiovn commented 3 years ago

https://github.com/jonathanpmartins/v-money3/blob/d307fec9cc39e4da938d9b440a61a9cfa367547d/src/BigNumber.js#L44-L60

I need to show only 2 precision points from a big decimal number, but it must not round when shrinking the precision.

It'd be a good feature to have and option to avoid rounding and just slice the numbers.

jonathanpmartins commented 3 years ago

Feature released on 3.17.6. Thanks for helping improve the package!

sougiovn commented 3 years ago

@jonathanpmartins well, ok you added the option into the BigNumber class. But as a user, we don't actually use class directly.

It's still needed to add the shouldRound option then the format function might use this config.

jonathanpmartins commented 3 years ago

Sorry, I really tried to speed up your request, but I failed understanding it all!

I did publish a commit with some changes. Can you take a look on it before I release a new version?

What are you trying to accomplish? Is this change made in format function enough?

sougiovn commented 3 years ago

@jonathanpmartins Sorry, I didn't want to rush you. I'm building an application to handle data from B3(Brazilian's Stock Exchange), and there are some calculation in which they simply cut the number precision instead of rounding it. So I was always getting a plus 0.01 when presenting the data. I was looking for replicate that behavior of simply cutting the precision portion.

Example: The calculation results to 137.9972 B3 uses: 137.99 But the lib default behavior is rounding the exceeded precision points, resulting in 138.00

jonathanpmartins commented 3 years ago

Is this good enough, if the feature is available in the format function? Or do you wish to have it present in the directive/component modules too?

sougiovn commented 3 years ago

@jonathanpmartins in the format function works for me so far. But shouldn't it be easy to add to component too? Like, it's just a new prop, right?

jonathanpmartins commented 3 years ago

Please, test out 3.18.0 and reopen this issue if necessary. Thanks