0

hi,

for a 'total cost' field in sql i used the data type 'money'.. in c# what data type should i use to match that of the sql?? decimal or float??

thanks

4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by Momerath
0

in the database using sql:

tblReservation fields:
-> TotalCost - money (dataType)

------------------------------------------------

C# class:

public class Reservation
{
float TotalCost;
}

OR

public class Reservation
{
decimal TotalCost;
}

Edited by missc: n/a

0

The most suitable dataType for these type of comparisons is string as the retrieved data is in String form. If you want to perform any calculation with totalCost you can temporarily convert it to double(not float or decimal it is much more flexible than the other two) and again store the result in a string. but as far as comparison is concerned use string instead of float or decimal.

0

The most suitable dataType for these type of comparisons is string as the retrieved data is in String form.

This is contrary to what Microsoft says. According to the SQL data types to CLR data mapping money is a decimal type.

Also using strings to compare numbers is a bad idea at best. Using strings which of these values is larger 11 or 2?

Edited by Momerath: n/a

0

This is contrary to what Microsoft says. According to the SQL data types to CLR data mapping money is a decimal type.

Also using strings to compare numbers is a bad idea at best. Using strings which of these values is larger 11 or 2?

thats how i think as well.. so should i use double with money or decimal ? since in sql i'm using money and i don't know what to use in c# to match

0

Always use decimal when doing calculations with money. It doesn't have the rounding problems that double or float will have.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.