Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Math.Round error

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

    Math.Round error

    Hi,

    I am trying to round to the nearest whole number 90 % of the count of a list but get the error;

    "The call is ambiguous between the following methods or properties: 'System.Math.Round(double, int)' and 'System.Math.Round(decimal, int)'"
    and this

    Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)

    This is my code;

    Code:
    y = Math.Round(myList.Count * 90/100,0);
    Last edited by GKonheiser; 10-23-2014, 08:50 AM.

    #2
    GKonheiser,

    Thank you for your note.

    You need to specifically cast the double or decimal type in this instance.

    (double)(myList.Count * 90/100)

    Use the above in your Math.Round() to get the value of myList.Count * 90/100 specifically as a double
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      im obviously not getting it, i tried,

      Math.Round(decimal)(list.count * 90/100)

      and a few other variations but its not liking it, what am i doing wrong, I want to round to the nearest whole number?

      Comment


        #4
        GKonheiser,

        You still need the () for the Math.Round method, that has not and will not change.

        Math.Round((double)(myList.Count * 90/100), 0);
        Cal H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ETFVoyageur, 04-30-2024, 06:05 PM
        10 responses
        71 views
        0 likes
        Last Post ETFVoyageur  
        Started by Graci117, Yesterday, 11:40 PM
        4 responses
        25 views
        0 likes
        Last Post Graci117  
        Started by cmtjoancolmenero, Today, 02:31 PM
        4 responses
        10 views
        0 likes
        Last Post cmtjoancolmenero  
        Started by mintos, 04-02-2024, 08:22 PM
        2 responses
        17 views
        0 likes
        Last Post mintos
        by mintos
         
        Started by Taddypole, Today, 02:25 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Working...
        X