onepub-dev / money.dart

Dart implementation of Money and Currency classes with Money formatter.
MIT License
60 stars 32 forks source link

Custom Formatting of negative Money values #14

Open andrewescutia opened 4 years ago

andrewescutia commented 4 years ago

Is there a way to customize the location of the negative value sign '-'. By default it displays negative values as "$-11.99". But what Im looking for is "-$11.99". I currently dont see a documented way to format this.

Thanks!

bsutton commented 4 years ago

No that isn't currently supported. A PR would be welcome :)

I won't be able to do this work any time in the near future as I'm a little over committed with other project but would be happy to provide some guidance as you go.

There are a couple of questions that would need to be answered. 1) what character do we us to represent the sign in the format. 'S' is already used. We could use a '-' char or is that a bad idea if someone wanted to explicitly place a '-' symbol in the format. The other question would be about supporting alternate -ve representations such as ($10.00) for -ve nos. color coding for -ve nos. 2) Making a change that is ideally backward compatible. This would mean that if no -ve symbol was included that current formats would work as they do now.

So maybe we need to support multiple formatters

e.g.

'#.00-'
'-#.00'
'-CCS#.00'
'CCS-#.00'
'CCS#.00-'
'(CCS#.00)'
'RCCS#.00'
'R-CCS#.00'
'R(CCS#.00)'

The 'R' indicates to color code the text. This idea seems problematic as the application of color is dependent on the UI framework in use. The R probably won't work for flutter as you need to apply a text style to a specific widget. For terminal apps the R might work if we applied ansi color coding. My feeling is that color its probably a bad idea at this point.

andrewescutia commented 4 years ago

Browsing around it appears that a couple of common approaches are to allow for the use of '-' or '()' to denote a negative monetary value as part defining the format (hard pressed to find a reason why anyone would want to use either of those to denote anything other then a negative so using those symbols should be safe and common practice.

The other approach would be to allow for the ability to explicitly define a negative format. with the current format defined being the positive format as well as a fallback to negative if one is not defined.

I think the latter may be a bit overkill and would prefer to just expand the format to also allow for '-' and '()' to denote negative values.

I could take a stab on a PR for it. thoughts?

bsutton commented 4 years ago

I agree with your idea.

Love to see pr.

On Tue, 11 Aug 2020, 12:45 am Andrew Escutia, notifications@github.com wrote:

Browsing around it appears that a couple of common approaches are to allow for the use of '-' or '()' to denote a negative monetary value as part defining the format (hard pressed to find a reason why anyone would want to use either of those to denote anything other then a negative so using those symbols should be safe and common practice.

The other approach would be to allow for the ability to explicitly define a negative format. with the current format defined being the positive format as well as a fallback to negative if one is not defined.

I think the latter may be a bit overkill and would prefer to just expand the format to also allow for '-' and '()' to denote negative values.

I could take a stab on a PR for it. thoughts?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/noojee/money.dart/issues/14#issuecomment-671399350, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG32OCCBWDKGZEKL6YNQNTSAABYTANCNFSM4PLX5YAQ .

btrautmann commented 10 months ago

Screenshot 2023-12-19 at 06 16 00

FWIW, I'm working with an API that allows the following currency formats (this specific screenshot is for the Euro. Other currencies allow for additional/different ones). I assume the design as proposed would break the one that contains a -.

bsutton commented 10 months ago

Are the dash and slash variants for the decimal place actually used any where?

Most of the formats could probably be accommodated by allowing a custom thousand delimiter and decimal delimiter.

The tricky one would be the last example with the group delimiter. In aware India uses a similar format and hasn't cube up with a solution.

Do you have examples of the formatter used for each output?

I don't think the negative formatter will be an issue.

On Tue, 19 Dec 2023, 10:17 pm Brandon Trautmann, @.***> wrote:

Screenshot.2023-12-19.at.06.16.00.png (view on web) https://github.com/onepub-dev/money.dart/assets/8343465/aab6ce7d-f05a-43db-92d7-a55093765ec4

FWIW, I'm working with an API that allows the following currency formats (this specific screenshot is for the Euro. Other currencies allow for additional/different ones). I assume the design as proposed would break the one that contains a -.

— Reply to this email directly, view it on GitHub https://github.com/onepub-dev/money.dart/issues/14#issuecomment-1862572468, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG32OFGQE3GGXT6HF7TTPDYKFZTXAVCNFSM4PLX5YA2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBWGI2TOMRUGY4A . You are receiving this because you commented.Message ID: <onepub-dev/money .@.***>

btrautmann commented 10 months ago

Do you have examples of the formatter used for each output?

Sorry, these formats are all from an API that I consume for my app (the YNAB API). Each of these formats is a choice a user has in determining how currency values in their budget are displayed. So ideally my app handles all of these. AFAIK it does, except the one you pointed out at the very bottom. I'm not exactly sure what would happen in that case 🙃

bsutton commented 10 months ago

I think the starting point will be to remove the invertseparator arg and replace it with the explicit decimal and group delimiter params you use in your example.

Whilst breaking I think it provides a significant benefit.

I think this would cover every example except for the last.

The one question is, do you allow

1.23- 1-23-

1.- 1--

1. 1-

The last two look problematic.

For parsing we could relax the position of the group separator which would allow us to accept the last variant in your examples but doesn't give us a way to format it.

We could add a left to right Arg for group separator which could handle the India scenario:

Ltr 1,000,00

Rtl 100,000

On Wed, 20 Dec 2023, 6:12 am Brandon Trautmann, @.***> wrote:

Do you have examples of the formatter used for each output?

Sorry, these formats are all from an API that I consume for my app (the YNAB API https://api.ynab.com/#formats). Each of these formats is a choice a user has in determining how currency values in their budget are displayed. So ideally my app handles all of these. AFAIK it does, except the one you pointed out at the very bottom. I'm not exactly sure what would happen in that case 🙃

— Reply to this email directly, view it on GitHub https://github.com/onepub-dev/money.dart/issues/14#issuecomment-1863335799, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG32OBPRSBBBXPXPUNMC2TYKHRJ5AVCNFSM4PLX5YA2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBWGMZTGNJXHE4Q . You are receiving this because you commented.Message ID: <onepub-dev/money .@.***>