how do I truncate to 2 decimal points?

I’m writing a script that reads a quicktime file and reports the frame rate. For most videos it works fine. For others, the script sees the frame rate having too many decimal places. This throws off some of my future calculations. For example, if a video reports a frame rate of : 59.947414548642

The TRUE rate should be 59.94

If I try rounding to the nearest hundredth, I get 59.95

Although this is close, it throws off my future calculations. I would like my script to return the value as 59.94

Here is my script. It normally selects a quicktime file in the beginning, but I simplified it for you and inserted the values instead.

Can anyone help me return a value of 59.94???

--set theFile to (choose file)
--tell application "QuickTime Player"
--	open (launch)
--	open theFile
--	tell document 1
--		tell (1st track whose kind is "Video")
set frameCount to 228 --count frames
--		end tell
set time_scale to 600 --time scale
set totalduration to 2282 --duration
set frameRate to (frameCount * time_scale) / totalduration
--	end tell
--	quit
--end tell

display dialog frameRate as string

May this post is of some help :slight_smile:

set myNumber to 59.947414548642

truncate(myNumber, 2) -- returns 59.94

on truncate(aNumber, decimalPlaces)
	
	set aNumeral to "" & aNumber
	
	if aNumeral does not contain "." then
		set aNumeral to aNumeral & "."
	end if
	
	repeat with i from 1 to decimalPlaces
		set aNumeral to aNumeral & "0"
	end repeat
	
	repeat with i from 1 to length of aNumeral
		if characters i thru -1 of aNumeral does not contain "." then exit repeat
	end repeat
	try
		return (characters (1) thru (i + (decimalPlaces - 1)) of aNumeral as string) + 0
	end try
end truncate