Announcement

Collapse
No announcement yet.

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 CaptainJack, 05-29-2026, 05:09 AM
        0 responses
        476 views
        0 likes
        Last Post CaptainJack  
        Started by CaptainJack, 05-29-2026, 12:02 AM
        0 responses
        317 views
        0 likes
        Last Post CaptainJack  
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        254 views
        1 like
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        340 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        305 views
        0 likes
        Last Post CarlTrading  
        Working...
        X