1. Re: Whats the problem in this function?<decoded from the

Steve Lee wrote:
>
> -- I made the function that returns the rounded-up,down,off(is it right
> expression? my english
> -- is somhow poor :) value on the given digit.
> -- but when used in the main program, i got a problem on calculating
> Round-Down process.
> -- an example blelow.
>
> global constant ROUND_UP = 1,   --¿Ã¸²
>     ROUND_DOWN = 0,  --³»¸²
>      ROUND_OFF = 0.5  --¹Ý¿Ã¸²
>
> global function round_number(atom flag, object number, integer digit)
> -- flag : ¿Ã¸²,³»¸²,¹Ý¿Ã¸²À» °áÁ¤
> -- number : °è»êÇÒ ¼ýÀÚ
> -- digit : ¹Ý¿Ã¸²(¿Ã¸²,³»¸²)ÇÒ ÀÚ¸®¼ö(¼Ò¼öÁ¡ ÀÌÇÏ´Â - ·Î Ç¥½Ã; -2 ->
> ¼Ò¼öÁ¡ÀÌÇÏ 2
> --     °ÀÚ¸®) ; 0Àº µÉ ¼ö ¾øÀ½, ÀÔ·ÂÇϸé "There's no digit 0!"¸¦ ¹Ýȯ
>
>  object answer
>
>  if digit = 0 then answer = "There's no digit 0!"
>   elsif digit < 0 then
>    answer = floor(number/power(10,digit+1)+flag)*power(10,digit+1)
>     elsif digit > 0 then
>      answer = floor(number/power(10,digit)+flag)*power(10,digit)
>  end if
>  return answer
> end function
>
> atom number
> object value
>
> number = 1648.174
>
> for i = 2 to -6 by -1 do
>  value = round_number(ROUND_DOWN,number,i)
>  if i = 0 then
>   puts(1,value&'\n')
>  else
>   printf(1,"%4.5f rounded down by digit %d into %4.5f \n",{number,i,value})
>  end if
> end for
>
> -- now result below
>
> --1648.17400 rounded down by digit 2 into 1600.00000
> --1648.17400 rounded down by digit 1 into 1640.00000
> --There's no digit 0!
> --1648.17400 rounded down by digit -1 into 1648.00000
> --1648.17400 rounded down by digit -2 into 1648.10000
> --1648.17400 rounded down by digit -3 into 1648.17000
> --1648.17400 rounded down by digit -4 into 1648.17300 -> problem starts to
> occur!! expecting
> --                                                       1648.17400!!
> --1648.17400 rounded down by digit -5 into 1648.17390
> --1648.17400 rounded down by digit -6 into 1648.17399
>
> -- I know many other excellent routines for this job but i still want to know
> WHAT IS THE
> -- PROBLEM IN MY ALGORITHM!!
>
> -- Steve.
>

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu