none
Which datatype for Currency / Money - Values is usefull?

    Question

  • Hello,

    which datatype did you choose?

    For which reason?

    THX

    Dieter


    -- EDV-Kommunikation Strassner e.K. www.strassner.biz
    Tuesday, April 26, 2011 10:46 AM

Answers

  • While the serialization and deserialization is not that hard I believe that using LINQ on that property would require you to modify the query string on the URL. While this is possible using the DataServiceContext.SendingRequest event, I strongly suspect that it is far more trouble than it is worth.

    I would be tempted to store the monetary value in a double to avoid the risk of someone forgetting it is in cents. Developers are used to a TimeSpan being expressed in different units but they are not used to money being expressed in cents.

    Wednesday, April 27, 2011 4:19 PM
    Answerer

All replies

  • Hi Dieter,

    I am presuming you are talking about "Table" storage.

    The only allowed data types in Table are under "Property Types" section in http://msdn.microsoft.com/en-us/library/dd179338.aspx.

    You can use either String or double data type for currency and use ToString or String.Format method to convert it into currency text.

    Please refere, http://msdn.microsoft.com/en-us/library/kfsatb94.aspx and http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx.

    HTH,


    Mahesh Devjibhai Dhola [Please mark best and acceptable replie(s) as the ANSWER(S)]
    Tuesday, April 26, 2011 11:15 AM
  • Hello Mahesh,

    thanks for your answer.

    Yes, I'm talking about TableStorage.

    The reason for my question is: perfomance, calling about LINQ and avoiding rounding errors by float/double-Datatypes

    My idea is to save all currency-values in INT64 (as CENT-Values).

    Is that is a good idea?

    THX
    Dieter

     


    -- EDV-Kommunikation Strassner e.K. www.strassner.biz
    Tuesday, April 26, 2011 12:44 PM
  • Hi Dieter,

    I understand your concern but I would say using string/double and convert them into currency format (please note, this is just for showing something like $xx.yy on UI) is still good idea.

    Even if you use INT64 as CENT-values, anyway you have to convert them into proper currency format to show somewhere in UI. So the performance impact is same in this case as well. And, if you are not going to convert them into currency format but you are only talking about storing the values in the storage, it doesn't matter which data type you are going to use.

    HTH,


    Mahesh Devjibhai Dhola [Please mark best and acceptable replie(s) as the ANSWER(S)]
    Tuesday, April 26, 2011 2:16 PM
  • Although probably overkill in this particular situation, it is possible to use the WritingEntity and ReadingEntity events to persist non-supported classes into Azure Tables. The idea is that in these events you serialize and deserialize data to and from supported formats. I did a post showing how to do this.
    Tuesday, April 26, 2011 6:47 PM
    Answerer
  • Hi,

    thanks for this suggestion! 

    How can I still query under LINQ?

    e.g. get all data Between amount 10000 AND 20000    (cent)

    Greetings from Germany

    Dieter


    -- EDV-Kommunikation Strassner e.K. www.strassner.biz
    Wednesday, April 27, 2011 6:47 AM
  • How can I still query under LINQ?

    If the datatype is double, we can directly use it like:

    var query = from entity in context.CreateQuery<Customer>("Customer")
                where entity.Money > 10000.0 && entity.Money < 20000.0
                select entity;

    If the datatype is string, it will be:

    var query = from entity in context.CreateQuery<Customer>("Customer")
                where double.Parse(entity.Money) > 10000.0 && double.Parse(entity.Money) < 20000.0
                select entity;


    Wednesday, April 27, 2011 8:21 AM
  • Hi zwc2,

    thanks for your answer.

    My question "How can I still query under LINQ?"  referred to Neil Mackenzie's answer of "serialize and deserialize data".

    Can I use your solution in serializing and deserializing data (Posting of Neil Mackenzie)?

    THX

    Dieter


    -- EDV-Kommunikation Strassner e.K. www.strassner.biz
    Wednesday, April 27, 2011 9:42 AM
  • While the serialization and deserialization is not that hard I believe that using LINQ on that property would require you to modify the query string on the URL. While this is possible using the DataServiceContext.SendingRequest event, I strongly suspect that it is far more trouble than it is worth.

    I would be tempted to store the monetary value in a double to avoid the risk of someone forgetting it is in cents. Developers are used to a TimeSpan being expressed in different units but they are not used to money being expressed in cents.

    Wednesday, April 27, 2011 4:19 PM
    Answerer
  • While the serialization and deserialization is not that hard I believe that using LINQ on that property would require you to modify the query string on the URL. While this is possible using the DataServiceContext.SendingRequest event, I strongly suspect that it is far more trouble than it is worth.

    I would be tempted to store the monetary value in a double to avoid the risk of someone forgetting it is in cents. Developers are used to a TimeSpan being expressed in different units but they are not used to money being expressed in cents.

    Hello Neil,
    ACK!

    Are Values stored in Double not transformed

    e.g. Double-Value 13  stored as 0,129999999999997 * 10^2

    How does LINQ deal with Double-Values in this case?

    I know similar problems from VB6 (... and VS2010-beginners)

    Greetings

    Dieter


    -- EDV-Kommunikation Strassner e.K. www.strassner.biz
    Thursday, April 28, 2011 9:04 AM