What is the best layer for formatting currency numbers?

I am using Javascript in frontend, C # as middle tier and Oracle 9i as DB.

What is the best practice when formatting numbers with 2 decimal precision in currency? And which layers should be preferred among any of these three layers?

Remembering that the User will be able to edit these amounts on several of my screens in the application.

+1


source to share


3 answers


Your decimal storage can be as high as 2 digits. Since you mention C # and Javascript, I can assume that you are using ASP.NET for your frontend.

Currency mapping must be handled in your ASP.NET code to render it based on your custom locale / culture.



For your gridviews and other C # display controls, you can use the string formatting option: {0:c}

to display the currency with the correct symbol and two decimal places.

+1


source


I would say to do this as close to the user as possible as it is practical. Not in the database anyway, since the DB won't know about the user's locale.



Update: Remember, when you format the currency, you are displaying information to the user that is actually correct. Currency formatting does not match currency conversion ...

+2


source


if you want to perform any mathematical operations on your data, it is much better to do the formatting in Javascript and add a currency symbol.

0


source







All Articles