Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Rounded numbers from print statement

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

    Rounded numbers from print statement

    Hi Folks,

    Newbee question: I want to express one value in relation to another as a percentage. When testing this in the output window I get rounded numbers only, either 1 or 0.

    The variable I tried is both double and float but output stays the same, the statement is below:

    _50PercDelta = (barsType.Volumes[CurrentBar].TotalVolume + barsType.Volumes[CurrentBar].MinSeenDelta) / barsType.Volumes[CurrentBar].TotalVolume;

    What am I missing here?


    #2
    Hello Diepy,

    Thanks for your post.

    We are seeing the result of integer math being assigned to a double because you are performing mathematical operations on integers and assigning the result to a double.

    You could consider casting (publicly available resource) the integers to type double, and we will then see a result from floating point arithmetic.

    We look forward to assisting.

    Comment


      #3
      Thanks Jim, that makes sense.

      So double would be fine for my purposes and I figured I would alter the statement like below.

      _50PercDelta = Convert.ToDouble((barsType.Volumes[CurrentBar].TotalVolume + barsType.Volumes[CurrentBar].MinSeenDelta)/ barsType.Volumes[CurrentBar].TotalVolume)

      The output window still shows rounded numbers though, anything I am missing still?

      Thanks

      Comment


        #4
        Hello Diepy,

        You are still performing math on integers, getting a result from integer math, AND THEN you are converting to a double, and assigning to the double variable.

        Try casting the integers before performing the math. I.E.

        ((double)(barsType.Volumes[CurrentBar].TotalVolume) + (double)(barsType.Volumes[CurrentBar].MinSeenDelta) / (double)(barsType.Volumes[CurrentBar].TotalVolume;

        OR

        (Convert.ToDouble(barsType.Volumes[CurrentBar].TotalVolume) + Convert.ToDouble(barsType.Volumes[CurrentBar].MinSeenDelta) / Convert.ToDouble(barsType.Volumes[CurrentBar].TotalVolume;

        Comment


          #5
          Thanks Jim, I see I was a too lazy programmer :-) Your suggestion did the trick, thanks for the help!



          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 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
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X