• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Round a number towards zero!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Round a number towards zero!


  • Subject: Re: Round a number towards zero!
  • From: Nigel Garvey <email@hidden>
  • Date: Sat, 19 Mar 2005 00:44:29 +0000

Christian Vinaa wrote on Fri, 18 Mar 2005 15:38:07 +0100:

>ok,  how do I then fx  round to  x decimals ?
>(and not to zero )

>where 0,1,2,3,4 gets rounded down  and 5,6,7,8,9 gets rounded up

  (* Truncate n to d decimal places, with or without rounding. *)
  on trnc from n onto d given rounding:rounding
    tell 10 ^ d
      tell n * ((10 ^ 0.5) ^ 2) * it -- fix for certain awkward floats
        if rounding then
          it div 5 - it div 10
        else
          it div 10
        end if
      end tell
      result / it
    end tell
  end trnc

  trnc from 321.245 onto 2 with rounding
  --> 321.25


More at:

<http://files.macscripter.net/scriptbuilders/ScriptTools/aRounderRound.sit>



NG
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Round a number towards zero!
      • From: Michelle Steiner <email@hidden>
  • Prev by Date: Re: Round a number towards zero!
  • Next by Date: Re: Round a number towards zero!
  • Previous by thread: Re: Round a number towards zero!
  • Next by thread: Re: Round a number towards zero!
  • Index(es):
    • Date
    • Thread