Dear Dynamicweb,
What is the difference between: CurrencyService.FormatCurrency and CurrencyService.Format, and when does it make sense to use the different formatting methods?
Best regards, Anders
Dear Dynamicweb,
What is the difference between: CurrencyService.FormatCurrency and CurrencyService.Format, and when does it make sense to use the different formatting methods?
Best regards, Anders
Hi Anders,
I can't explain exactly why we have two entry points like this. Probably legacy, but here is the difference:
Format tries to use the provided currency's cultureinfo to use a "standard" string.format with a "C" format, or "N" if symbol should be excluded (as per the currency object). It falls back on FormatCurrency, if it cannot format with the cultureinfo.
FormatCurrency uses the cultureinfo from the thread/rendering context, and does a custom formatting based upon this cultureinfo. "#,##0.0" or "#,##0.00" depending upon rounding settings. Then, if usesymbol is true, it adds the currency symbol at the front or back of the string, based upon if SymbolPlace == 0 or not.
I would personally always use "Format" because I think string.Format() with "C" or "N" is well defined and easier to understand.
Hope this explaination helps.
BR
Martin
Dear Martin,
Thanks for the explanation. Would it make sense to only have one formatting method to avoid confusing?
Best regards, Anders
At some point currencies got the ability to have regional settings on them. Before, they used custom settings to control currency formatting. That is why there are 2 options - old and new.
Format is the new and uses regional settings if present - otherwise falls back to FormatCurrency. So yes, use Format.
We cannot remove the old method as it is still in use and public and would break api. We could mark it as obsolete, but it is still not...
Dear Nicolai,
It would be great marking the old method as obsolete, as we then know what method to use.
Best regards, Anders
You must be logged in to post in the forum