Results 1 to 9 of 9

Thread: function RoundDec(number: extended; decimals: integer): extended

  1. #1
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default function RoundDec(number: extended; decimals: integer): extended

    I made this while experimenting with Delphi and changed it to run in Scar. I though it may be useful to someone, and thus it made its way here:
    SCAR Code:
    function RoundDec(number: extended; decimals: integer): extended;
    begin
      Result := Round(number * Pow(10, decimals)) / Pow(10, decimals);
    end;

    You can test it with this:
    SCAR Code:
    program New;

    function RoundDec(number: extended; decimals: integer): extended;
    begin
      Result := Round(number * Pow(10, decimals)) / Pow(10, decimals);
    end;

    begin
      Writeln(FloatToStr(RoundDec(1.23456789, 8)));
    end.
    And change the 8 to different numbers to see it in action.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  2. #2
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Nice function, i was so annoyed when i put:
    SCAR Code:
    program New;
    begin
      Writeln(FloatToStr(7 div 2));
    end.

    and it says:
    SCAR Code:
    Successfully compiled
    3
    Successfully executed


  3. #3
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    div automatically rounds it down - if you don't want it to do that, then use / with variables or /blah.0 if not (so 7 / 2.0) so it knows to return a float
    (Wizzup? posted it btw so it must be true)
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  4. #4
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Actually, in scar, div and / are exactly the same. It's only in Delphi that div floors the quotient. To get a float as a result, at least one number must be a float.

  5. #5
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Just wanted to ask whats a float?

  6. #6
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by NaumanAkhlaQ View Post
    Just wanted to ask whats a float?
    A decimal number. Same meaning as an extended.

    EDIT: This function should be included in SCAR.

  7. #7
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Glad you think it should be included in Scar - I just thought it may be useful to someone
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  8. #8
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default

    Unfortunately unless you can convince me it's that useful, I don't think it should be included in SCAR...

  9. #9
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    The only time I could think of when you would use it would be for visual effect, but I didn't think it would be added anyway.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Extended to integer
    By cathering_ in forum OSR Help
    Replies: 2
    Last Post: 08-18-2007, 03:58 AM
  2. changing Extended into Integer
    By fORCE_wORKS in forum OSR Help
    Replies: 2
    Last Post: 01-22-2007, 11:54 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
  •