Round Up number ? - Programmers Heaven

#### 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 ?

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!

• 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!

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]

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

• 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]

• 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!
:

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

• 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!