display big numbers

I need to display big numbers (1000 up to 99 999)

However AS displayed them in form of 9E+99
Is there smart way to force AS to suit my needs (except of manipulation with separate characters)?

return 3000 + 99999

returned

for me so I don’t know why yours would go into exponents

my numbers are result of previous calculations and AS stores them in exponential format

you get the exponential form because your numbers aren’t integers.
If you are interested only by the integer value,
you may coerce them as integers or round them.


set n1 to 9999999
set n2 to 527.11
set n3 to 35.71

set n4 to n1 * n2 / n3
log n4
log n4 as integer
log (round (n4) rounding as taught in school)

Yvan KOENIG (from FRANCE mardi 5 mai 2009 15:52:07)

And if integers aren’t the solution for you (per Yvan), Apple’s suggestion is to convert the numbers to text for display. This is from Apple’s web site (variables renamed to suit my own conventions):

--convert scientific notation
--(from Apple's web site)
on number_to_text(this_number)
	set this_number to this_number as text
	if this_number contains "E+" then
		set x to the offset of "." in this_number
		set y to the offset of "+" in this_number
		set z to the offset of "E" in this_number
		set the decimal_adjust to characters (y - (length of this_number)) thru ¬
			-1 of this_number as string as number
		if x is not 0 then
			set the first_part to characters 1 thru (x - 1) of this_number as string
		else
			set the first_part to ""
		end if
		set the second_part to characters (x + 1) thru (z - 1) of this_number as string
		set the converted_number to the first_part
		repeat with i from 1 to the decimal_adjust
			try
				set the converted_number to ¬
					the converted_number & character i of the second_part
			on error
				set the converted_number to the converted_number & "0"
			end try
		end repeat
		return the converted_number
	else
		return this_number
	end if
end number_to_text

Interesting notes on rounding numbers, for the curious:

http://en.wikipedia.org/wiki/Rounding

They way that is taught in school is statistically flawed. :wink:

What would be the AppleScript for “banker’s rounding” or unbiased rounding?

Here is some testing code that uses some numbers from the Wikipedia article:

on run
	local tests, m, test, r
	(*
	* first half of test numbers from http://en.wikipedia.org/wiki/Rounding#Round-to-even_method
	* second half of test numbers based on second half but with odd staring number
	*)
	set tests to {¬
		{304.48, 304}, ¬
		{304.5, 304}, ¬
		{304.52, 305}, ¬
		{-304.48, -304}, ¬
		{-304.5, -304}, ¬
		{-304.52, -305}, ¬
		{305.48, 305}, ¬
		{305.5, 306}, ¬
		{305.52, 306}, ¬
		{-305.48, -305}, ¬
		{-305.5, -306}, ¬
		{-305.52, -306} ¬
			}
	
	set m to {}
	repeat with test in tests
		set r to round first item of test rounding to nearest
		if r is not equal to second item of test then ¬
			set end of m to {contents of test, r}
	end repeat
	
	m --> {}; "rounding to nearest" rounds N.5 to nearest even integer (the so-called unbaised rounding)
end run

But note that round from StandardAdditions is not fast (since it is a OSAX, it suffers as compared to bare AppleScript). If you need speed, you might adopt Nigel Garvey’s rounding handlers. Using rndIEEE form the that library to do 100 rounds of the above testing took my machine 2 seconds. Using round to do the same work took my machine 62 seconds.