Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Round Up number ?

agungdeppeagungdeppe Posts: 3Member
I have a problem with math function, I don't know hoe to round up the number. For example if I had 1.1 it will round up to 2, 1.9 to 2 and soon.
With round up I get 1.1 to 1 and 1.9 to 2
All I want is if 1.xx will round up to 2 and soon.
Sorry, my english is very bad!
I need your help....please!

Comments

  • NoamNoam Posts: 130Member
    : I have a problem with math function, I don't know hoe to round up the number. For example if I had 1.1 it will round up to 2, 1.9 to 2 and soon.
    : With round up I get 1.1 to 1 and 1.9 to 2
    : All I want is if 1.xx will round up to 2 and soon.
    : Sorry, my english is very bad!
    : I need your help....please!

    do a search on the subject. there was a post a while back about the same thing, that god several replies as i recall.
    search for "trunc" or "round" or "round up"..one of them should find the right message.

    if you're too lazy, just use round(trunc(n)+0.51) and that should work. should work with 0.5 as well but just to be on the safe side..

    **********
    Make something idiot proof and some1 will make a better idiot..
    [blue]//Noam[/blue]


  • MoustacheMoustache Posts: 38Member
    i think trunc(n)+1 should work...
    M



  • ManningManning Posts: 1,621Member
    : i think trunc(n)+1 should work...
    : M
    :
    :
    :

    But if N is an integer, it will still round it up. I think he only wants to round up decimal numbers.

    [code]
    function RoundDecimal(X: Extended): Integer;
    begin
    if (X - Trunc(X) <> 0) then // there is a decimal...
    Result := Trunc(X) + 1 // ...so we round up
    else // there is no decimal...
    Result := Trunc(X); // ...so we just return X
    end;
    [/code]

  • majesticmajestic Posts: 8Member
    : I have a problem with math function, I don't know hoe to round up the number. For example if I had 1.1 it will round up to 2, 1.9 to 2 and soon.
    : With round up I get 1.1 to 1 and 1.9 to 2
    : All I want is if 1.xx will round up to 2 and soon.
    : Sorry, my english is very bad!
    : I need your help....please!
    :

    result := round(some real number+0.5);

  • ManningManning Posts: 1,621Member
    : : I have a problem with math function, I don't know hoe to round up the number. For example if I had 1.1 it will round up to 2, 1.9 to 2 and soon.
    : : With round up I get 1.1 to 1 and 1.9 to 2
    : : All I want is if 1.xx will round up to 2 and soon.
    : : Sorry, my english is very bad!
    : : I need your help....please!
    : :
    :
    : result := round(some real number+0.5);
    :

    If you really want to use the simpler Round method to round up, it would be Result := Round(x + .49). That way 1 + .49 = 1.49, and would not be rounded up.

    But if x is going to have many decimal places, even that wont work though. For example, if X was 1.001, then 1.001 + .49 = 1.491, and will still be rounded down to 1 instead of 2.

Sign In or Register to comment.