Using currency $ format with sql server?

末鹿安然 提交于 2019-12-02 23:13:23

问题


I have data in my sql database like 645.000 and i need to format it to include currency symbols e.g., $645.000

How can I achieve this in SQL?


回答1:


You don't need to and should not be formatting it in SQL Server - instead it's your application that needs to format it for the UI.

You didn't say what your application is coded in, e.g. in C# we could use

Label1.Text = string.Format("Amount is {0:c}", amount);

Then you can be sure that not only will it use the correct currency symbol, it will also use the correct decimal and thousands separator symbols.




回答2:


SQL server has no control over how numbers are displayed in your client application. Modify the application settings, Windows control panel or your program code to change the way numbers are displayed.




回答3:


what is the datatype of your column?

In general currency prefixes should be added only in the UI (User Interface) and at the database level you should work just with numbers. Best data type to store money values is MONEY.




回答4:


Refer this if you really need to do this from the database rather than from the UI.

http://www.java2s.com/Code/SQLServer/Data-Type/Formatmoneycurrency.htm



来源:https://stackoverflow.com/questions/4883865/using-currency-format-with-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!