Showing posts with label decimal. Show all posts
Showing posts with label decimal. Show all posts

Thursday, March 22, 2012

Cursed with trailing whitespace or trailing 0's

I have a databound textbox that is used to store a decimal value.

If my sql table stores this column as a decimal(2,2), then all of the numbers entered into the field will automatically put decimal places in that I don't want. For example, 45 becomes 45.00... 34.5 becomes 34.50.

If I set the sql table to nchar(10) and the dataset to system.string (max length of -1), then the number looks the way I would like it, however after a datatable update I end up with trailing whitespace after the number - filling up the rest of the unused 10 characters. For example, "45" becomes "45 " (8 spaces afterwards).

Does anybody know how I can fix this? I would prefer to store the numbers in SQL as a string (nchar(10))... but I don't know how to get rid of that darned whitespace. I would like to remove it at the database level and not at the client level if at all possible.

Thanks!

Using char means that you want to have fixed length attributes. using Varchar would use only the space that is needed for storing the attribute. You have to keep in mind that the insert behaviour is determined by your inserting application. if the application do insert "45 " then you have to manuipulate the application ratehr than the database. But normally you should only switch to a variable character length field, e.g. in this case VARCHAR(10).

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

Sunday, March 11, 2012

Currency being rounded up in Report

I am displaying an amount of money to two decimal places in a field in a report.

If I run the stored procedure in sql server the amounts are displayed to two decimal places like so €31.75.

But when I run the report the amount is returned as so €32.00, it is being rounded up to the nearest euro.

Anyone any ideas how to solve this?

macca

Figured this out myself.