views:

327

answers:

3

I use Javascript on frontend, C# as middle layer and Oracle 9i as DB.

What is the best practice when formatting numbers with 2 decimal precision into a currency? And what layers should be preferred amongst any of these three layers?

Keeping in mind that the User will be able to edit these amounts on a few of my screens on the application.

+2  A: 

I would say do it as close to the user as it is practical. Not in the database anyway, since the DB will not be aware of the locale of the user.

Update: Be aware when doing currency formatting that you are displaying information to the user that is actually correct. Currency formatting is not the same as currency conversion...

Fredrik Mörk
+1  A: 

The storage of your decimal can be at a higher precision than 2 digits. Since you mention, C# and Javascript, I can assume that you are using ASP.NET for your front-end.

The display of the currency has to be handled in your ASP.NET code, to display it based on your user's locale/cultureinfo.

For your gridviews and other display controls, in C#, you can use the string formatting option: {0:c} to display the currency with the correct symbol and 2 decimal places.

Jose Basilio
A: 

if you want to perform any mathematical operations on your data it will be much better to to the formatting in javscript and add the currency symbol.

Simon_Weaver