CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Feb 2010
    Posts
    4

    Rounding or Modulus

    I have had only one programming class a long time ago and am in over my head (Shake is pretty dumb.) All I want to do is round down to the nearest 0.25 increment.

    Say my number is 1879.92 (closer to 1880 than 1879.75), I would like a value of 1879.75 returned.
    If the number is 1764.27, I would like 1764.25 returned.

    I think modulus only works for returning whole numbers.

    Is there an easier way than using a nested if statement like?

    double price;
    double roundedprice;
    double remainder;

    //price is calculated earlier in another section of code

    roundedprice = Round(price);
    remainder = price - roundedprice;

    if (remainder >= 0.75) { price = roundedprice + 0.75 }
    if (remainder >= 0.50) { price = roundedprice + 0.50 }

    if (remainder >= 0.25) { price = roundedprice + 0.25 }

    if (remainder >= 0.00) { price = roundedprice + 0.00 }

    Any thoughts?

    The actual part of code that I am trying to insert this into follows:
    Code:
                // Condition set 1
                if (DefaultInput[0] > ChandelierSAR(5, 3.5).Chandelier[0]
                    && ToTime(Time[0]) > ToTime(8, 30, 0)
                    && ToTime(Time[0]) < ToTime(15, 0, 0))
                {
                    EnterShortStopLimit(DefaultQuantity, ChandelierSAR(5, 3.5).Chandelier[0], ChandelierSAR(5, 3.5).Chandelier[0], "");
                    Alert("MyAlert0", Priority.High, "", "", 1, Color.White, Color.Black);
                }
    
                // Condition set 2
                if (DefaultInput[0] < ChandelierSAR(5, 3.5).Chandelier[0]
                    && ToTime(Time[0]) > ToTime(8, 30, 0)
                    && ToTime(Time[0]) < ToTime(15, 0, 0))
                {
                    ExitShortStopLimit(ChandelierSAR(5, 3.5).Chandelier[0], ChandelierSAR(5, 3.5).Chandelier[0], "", "");
                }
    Last edited by Master Shake; February 17th, 2010 at 10:03 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured