D
Dermot Moynihan
Hi guys
Got a Ruby book yesterday from Santa, and am a bit stuck
Searched the pickaxe and some Perl books (left over after an earlier
failed attempt at programming), and this list and Googled and found
nothing useful.
Some examples might make the question clear:
Let's say that after a calculation I get 4.1200056 and I want to round
it up to 5.
When the calculation comes to a number like 4.0 I want it left at 4.
The way I've been dealing with it is that after I get a figure like,
let's say, 7.312456 I turn it into an integer (it then becomes 7) and
then I add 1 getting, in this case, the round number 8.
This works fine except on the occasions when the answer to the
calculation is already a round number like, let's say 6 or 6.0. Turning
it into an integer keeps it 6 but adding 1 makes it a 7. In such a case
I need it to stay at 6.
So, when it's got some figures (other than a single zero) after the
decimal point I want to round it up to a whole number (no decimal point)
but when it has only a single zero after the decimal point I want it
left alone except to have the decimal point and the zero disappear.
Sorry if there is a lack of clarity.
Appreciate any help
all the best
Dermot
Got a Ruby book yesterday from Santa, and am a bit stuck
Searched the pickaxe and some Perl books (left over after an earlier
failed attempt at programming), and this list and Googled and found
nothing useful.
Some examples might make the question clear:
Let's say that after a calculation I get 4.1200056 and I want to round
it up to 5.
When the calculation comes to a number like 4.0 I want it left at 4.
The way I've been dealing with it is that after I get a figure like,
let's say, 7.312456 I turn it into an integer (it then becomes 7) and
then I add 1 getting, in this case, the round number 8.
This works fine except on the occasions when the answer to the
calculation is already a round number like, let's say 6 or 6.0. Turning
it into an integer keeps it 6 but adding 1 makes it a 7. In such a case
I need it to stay at 6.
So, when it's got some figures (other than a single zero) after the
decimal point I want to round it up to a whole number (no decimal point)
but when it has only a single zero after the decimal point I want it
left alone except to have the decimal point and the zero disappear.
Sorry if there is a lack of clarity.
Appreciate any help
all the best
Dermot