Re: Rounding off in AppleScript
Re: Rounding off in AppleScript
- Subject: Re: Rounding off in AppleScript
- From: Vince <email@hidden>
- Date: Tue, 12 Apr 2005 14:54:38 +0200
Try this:
<x-tad-bigger>roundThis</x-tad-bigger><x-tad-bigger>(75.5436, 2) --</x-tad-bigger><x-tad-bigger>> 75.54 </x-tad-bigger><x-tad-bigger>
</x-tad-bigger><x-tad-bigger>on</x-tad-bigger><x-tad-bigger> </x-tad-bigger><x-tad-bigger>n</x-tad-bigger><x-tad-bigger>, </x-tad-bigger><x-tad-bigger>numDecimals</x-tad-bigger><x-tad-bigger>)
</x-tad-bigger><x-tad-bigger>set</x-tad-bigger><x-tad-bigger> </x-tad-bigger><x-tad-bigger>x</x-tad-bigger><x-tad-bigger> </x-tad-bigger><x-tad-bigger>to</x-tad-bigger><x-tad-bigger> 10 ^ </x-tad-bigger><x-tad-bigger>numDecimals</x-tad-bigger><x-tad-bigger>
(((</x-tad-bigger><x-tad-bigger>n</x-tad-bigger><x-tad-bigger> * </x-tad-bigger><x-tad-bigger>x</x-tad-bigger><x-tad-bigger>) + 0.5) </x-tad-bigger><x-tad-bigger>div</x-tad-bigger><x-tad-bigger> 1) / </x-tad-bigger><x-tad-bigger>x</x-tad-bigger><x-tad-bigger>
</x-tad-bigger><x-tad-bigger>end</x-tad-bigger><x-tad-bigger> </x-tad-bigger><x-tad-bigger>roundThis</x-tad-bigger>
Vince
On Apr 12, 2005, at 2:21 PM, Kumar Shailove wrote:
Hello list,
Does there exist any AppleScript primitive that rounds off a floating
point number up to a desired number of decimal points, e.g.
RoundOff(4.213452, 2)
Could round off the number and return me 4.21
And similarly
RoundOff(4.98123, 0)
Returns me 5.00
TIA.
_______________________________________________
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
_______________________________________________
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