Re: Round off or up

• To: mathgroup at smc.vnet.net
• Subject: [mg23825] Re: Round off or up
• From: Hartmut Wolf <hwolf at debis.com>
• Date: Sat, 10 Jun 2000 03:00:43 -0400 (EDT)
• Organization: debis Systemhaus
• References: <8hfgpp\$i5f@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```JikaiRF schrieb:
>
> Dear members of MathGroup,
>         I have a trouble manipulating Mathematica.
>
> My trouble is as follows:
> Consider a fractional number and transform it into decimals.  In this case,
> there could be left many decimals.  Then, I need to round the third decimal
> point as follows:
>         If they are larger than six digits, it should be rounded up from the third
> decimal points and rounded off if smaller than five.
>         Take examples;
>         1/17= 0.05882...  the fractional number should be expressed as 0.06.
>         1/18= 0.0555...   the fractional number should be expressed as 0.05.
>
>         I'd like to know how to program Mathematica to depict the above story.
>

Tja, Fujio, to me it's difficult to guess what you want. So I can't assign a
mathematical meaning to "a fractional number ... larger than six digits".
So *any* fractional number == rational has an *infinite* number of decimal
digits if the denominator contains a prime factor other than 2 or 5.

It may not be what you want, but I'll show you how "normally" numbers are rounded
to two digits:

conventionalRound[num_]:= N[Round[num 100]/100]

With[{t = Table[1/n, {n, 15, 25}]}, Transpose[{t, conventionalRound /@ t}]]

{{1/15, 0.07}, {1/16, 0.06}, {1/17, 0.06}, {1/18, 0.06},
{1/19, 0.05}, {1/20, 0.05}, {1/21, 0.05}, {1/22, 0.05},
{1/23, 0.04}, {1/24, 0.04}, {1/25, 0.04}}

However there seems to be a problem with this "conventionalRound" if you look at

t2 = 2 + Table[5/1000 n, {n, 0, 12}]

{2, 401/200, 201/100, 403/200, 101/50, 81/40, 203/100,
407/200, 51/25, 409/200, 41/20, 411/200, 103/50}

conventionalRound /@ t2

{2., 2., 2.01, 2.02, 2.02, 2.02, 2.03, 2.04, 2.04, 2.04, 2.05, 2.06, 2.06}

This may well appear as a bug, yet its none! This is exactly the way mathematicians
used to round numbers they calculated (by hand) in former times, e.g. for math
tables, as is described in Bronshtein, Semendyayev (on p.97 of my german
translated version of the 6th russion edition, Moskow 1956).

This is not the same as merchants like to do it, and perhaps that depends on
whether they buy or sell, and perhaps even on other cultural factors. For short,
let's assume they sell:

merchantRound[num_] := N[Floor[num 100 + 1/2]/100]

Perhaps when they buy the would like only to pay for

whenbuyRound[num_] := N[(Ceiling[num 100 + 1/2] - 1)/100]

Kind regards, Hartmut

```

• Prev by Date: Need help with integration.
• Next by Date: Re: Re: programming DeleteRepetitions
• Previous by thread: Round off or up
• Next by thread: Re: Integral Convergence