Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 14, 2006, 12:39 PM   #1
crd26
macrumors newbie
 
Join Date: Aug 2006
How to edit number precision in Applescript??

I have been learning Applescript recently and I can't figure out how to format the precision of a number. I have looked through forums and have looked through a couple of books as well as the Applescript Language Guide.

The "round" command comes close but isn't exactly what I need.

What I need in the end it to round numbers to the nearest two decimal places.

example : 18.094898203 to 18.09

Thanks for any help!
__________________
Tadow
crd26 is offline   0 Reply With Quote
Old Aug 14, 2006, 01:23 PM   #2
Sayer
macrumors 6502a
 
Sayer's Avatar
 
Join Date: Jan 2002
Location: Austin, TX
Quote:
Originally Posted by crd26
I have been learning Applescript recently and I can't figure out how to format the precision of a number. I have looked through forums and have looked through a couple of books as well as the Applescript Language Guide.

The "round" command comes close but isn't exactly what I need.

What I need in the end it to round numbers to the nearest two decimal places.

example : 18.094898203 to 18.09

Thanks for any help!
Use this:

Code:
(* format is roundThis(inDec, precision) *)

roundThis(75.5436, 1) --this will round to 75.5

on roundThis(n, numDecimals)
   set x to 10 ^ numDecimals
   (((n * x) + 0.5) div 1) / x
end roundThis
There is this invention called "Google" that actually lets you search for things you are looking for the answers to your question. Trully amazing, really.
__________________
Obama is a true statesman whose experience as a state senator, half-term US Senator & guest lecturer in a Constitutional Law class has fully prepared him to take control of our nuclear arsenal.-Me
Sayer is offline   0 Reply With Quote
Old Aug 14, 2006, 01:54 PM   #3
crd26
Thread Starter
macrumors newbie
 
Join Date: Aug 2006
I appreciate your help.

My looking through Google didn't pay off for me. I'm glad it did for you and thank you for sharing your findings.
__________________
Tadow
crd26 is offline   0 Reply With Quote
Old Aug 15, 2006, 02:49 PM   #4
SC68Cal
macrumors 68000
 
Join Date: Feb 2006
Can't you just use a double variable?

Then again, I have not gone that in depth into applescript using numbers, that's where I just fall back to Java.

EDIT: Applescript doesn't support double types. Not suprised, but it's kind of an expected features, you know?

Last edited by SC68Cal; Aug 15, 2006 at 02:58 PM.
SC68Cal is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Precision tools? forza69 iPhone 3 Oct 30, 2013 01:12 AM
error number -1728 Applescript & some issues with spot nellbern Mac Programming 1 Jan 22, 2013 08:36 PM
atrun precision elchemor Mac Programming 2 Jan 2, 2013 11:49 PM
Edit Number on telephone app hrv888 iPhone 3 Oct 31, 2012 09:00 PM
Creating a random number within a URL using Applescript moorbull Mac Programming 1 Jul 19, 2012 09:16 AM

Forum Jump

All times are GMT -5. The time now is 07:55 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC