Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert smallmoney to something c# [closed]

I have database column as "Salary". I'm keeping salary records of employees in this column as smallMoney. With C# I can insert this column value like "2000". After that I saw that columns value is "2000,00" in database. I need to get this value back like "2000" as string to update in my program. Because my program works like this. So, to use this value again, how can I convert this smallMoney to something to use effectively for my program? (Int "2000" or String "2000" is ok for my program)

I researched but couldn't find solution. Could anyone say how I do this?

like image 944
TwoEngineersOneBody Avatar asked Dec 14 '15 00:12

TwoEngineersOneBody


1 Answers

The SQL smallmoney is equal to a C# decimal. So after retrieving it from the database, you could convert it to an int. (You will lose the any decimal numbers though) OR you may use string formatting to only show the whole numbers.

For example:

// Create example value from database
decimal dSalary = 2000.00m;

int iSalary = Convert.ToInt32(dSalary);

Or you could keep it a decimal and just use string formatting, like this:

string Result = dSalary.ToString("0");
like image 112
Moon Avatar answered Sep 22 '22 03:09

Moon