Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strange Data Type Issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Strange Data Type Issue

    Hi,

    I was trying to perform an order of magnitude calculation when I ran into the following issue:

    double rawPrice = (Open[0] + High[0] + Low[0] + Close[0]) * 0.25;
    int magnitude = Math.Floor(Math.Log10(Math.Abs(rawPrice)));

    This will not compile even though it should.

    I had to do an explicit cast to get this to compile; i.e.

    double rawPrice = (Open[0] + High[0] + Low[0] + Close[0]) * 0.25;
    int magnitude = (int)Math.Floor(Math.Log10(Math.Abs(rawPrice)));

    Am I missing something here? Please advise. Thank you very much.

    #2
    Hello,

    I dont see an issue. This would be expected and is part of c# programming language.

    Datatype that you did the math functions to was of oringal type double. Therefor no matter what calculations you do, even if the double turns into what would fit nicely in an int. It is still a double (Due to the memory assigned for the var) and the compiler will flag you with error if you attempt to assign this to an int.

    Therefor to get the compile to let you compile you must put the type cast in to tell the compile you know what your doing and its ok if data loss occurs. (Even though in your case most likely no data loss if the value no longer has a decimal after it.)

    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      Hi Brett,

      My apologies. Of course you are correct. This was a dumb question on my part - brain freeze. Just couldn't see it at the time. Sorry to have taken up your time.
      Thank you for your reply.

      Comment


        #4
        No problem, glad to be of help.
        BrettNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        569 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        548 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X