Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rounding Value #7

Closed
LaksamanaGuntur opened this issue Jul 29, 2019 · 1 comment
Closed

Rounding Value #7

LaksamanaGuntur opened this issue Jul 29, 2019 · 1 comment
Assignees
Labels
Improvement Idea not an issue This is not an issue wontfix This will not be worked on

Comments

@LaksamanaGuntur
Copy link

LaksamanaGuntur commented Jul 29, 2019

Describe the bug
I get a problem with rounding value

To Reproduce
your sample :
FlutterMoneyFormatter fmf = FlutterMoneyFormatter(
amount: 12345678.9012345
);
and output with print(fo.compactNonSymbol); is 12.30M

My sample :
i change amount with 12355678.9012345 (change number four to five)
and output with print(fo.compactNonSymbol); is 12.40M

Expected behavior
My Expectation is 12.35

Screenshots

Screen Shot 2019-07-29 at 12 26 56

Smartphone (please complete the following information):

  • Device: [Xiaomi Redmi Note 5]
  • OS: [8.1]

Thanks!

@fadhly-permata
Copy link
Owner

fadhly-permata commented Aug 9, 2019

English Version:
Hi @LaksamanaGuntur, actually this is not part of flutter_money_formatter, the rounding results are obtained from the intl dependency.

However, as far as I know, rounding will usually use the round-up / round-down method by referring to the number on the right. So if we pay attention, the reason number 12355678.9012345 becomes 12.40M is, we will only take the first 4 digits (in your case that is, 1235), and the fourth number is 5, so the rounding method that will be used is definitely using the round-up method, and the result of rounding up from 1235 is 1240.

Remember, in the basic concept of rounding, the numbers 1,2,3,4 have definitely experienced round-down, and the numbers 5,6,7,8,9 have definitely been rounded up.

as an example:

525 = 500
717 = 700
1,250 = 1,300
2,781 = 2,800
4,524 = 4,500
5,359 = 5,400
6,168 = 6,000 + 100 + 68 = 6,000 + 100 + 100 = 6,200
6,998 = 6,000 + 900 + 98 = 6,000 + 900 + 100 = 7,000
10,343 = 10,000 + 300 + 43 = 10,000 + 300 + 0 = 10,300
7,423 = 7,400

Maybe if possible, in the next version I will add round-up and round-down features (by ignoring the basic concept of rounding numbers).

** N.B: **
Please review the concept of rounding, and as an additional reference from me, (since you are Indonesian) this is a good article that discusses rounding numbers.


Versi Indonesia
Hi @LaksamanaGuntur , sebetulnya hal ini bukan merupakan bagian dari flutter_money_formatter, hasil pembulatan tersebut didapat dari dependency intl.

Namun, sepanjang yang saya tau, pembulatan biasanya akan menggunakan metode pembulatan ke angka terdekat (round-up/round-down) dengan mengacu pada angka disebelah kanan. Jadi bila kita perhatikan, alasan angka 12355678.9012345 menjadi 12.40M adalah, kita hanya akan mengambil 4 digit pertama (pada kasus Anda yakni, 1235), dan angka ke-empat adalah 5, sehingga metode pembulatan yang akan digunakan sudah pasti menggunakan metode round-up (pembulatan ke-atas) dan hasil pembulatan ke atas dari 1235 adalah 1240.

Ingat, pada konsep dasar pembulatan, angka 1,2,3,4 sudah pasti mengalami pembulatan round-down, dan angka 5,6,7,8,9 sudah pasti mengalami pembulatan ke-atas.

sebagai contoh:

525 =  500
717 = 700
1.250 = 1.300
2.781 = 2.800
4.524 = 4.500
5.359 = 5.400
6.168 = 6.000 + 100 + 68 = 6.000 + 100 + 100 = 6.200
6.998 = 6.000 + 900 + 98 = 6.000 + 900 + 100 = 7.000
10.343 = 10.000 + 300 + 43 = 10.000 + 300 + 0 = 10.300
7.423 = 7.400

Mungkin bila memungkinkan, pada versi berikutnya akan saya tambahkan fitur round-up dan round-down (dengan mengabaikan konsep dasar pembulatan angka).

N.B:
Silahkan pelajari kembali konsep pembulatan, dan sebagai referensi tambahan dari saya, (berhubung Anda orang Indonesia) maka ini artikel bagus yang membahas mengenai pembulatan angka

@fadhly-permata fadhly-permata added the wontfix This will not be worked on label Aug 9, 2019
@fadhly-permata fadhly-permata pinned this issue Aug 9, 2019
@fadhly-permata fadhly-permata self-assigned this Aug 11, 2019
@fadhly-permata fadhly-permata added the not an issue This is not an issue label Aug 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Idea not an issue This is not an issue wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants