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 Hwop38, 05-04-2026, 07:02 PM
        0 responses
        168 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by CaptainJack, 04-24-2026, 11:07 PM
        0 responses
        322 views
        0 likes
        Last Post CaptainJack  
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        246 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        350 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        179 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Working...
        X