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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        152 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        87 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        131 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        127 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        106 views
        0 likes
        Last Post CarlTrading  
        Working...
        X