NOT Exponent number

i hope this is something easy & i am just being an ignorant fool
how do i get a return that isnt automatically formated as an Exponent number
or for that matter, keep it as a normal number when entering into code

set arse to ("4567189123" as integer) log result -- 4.567189123E+9 -- AAAAAAArrrrrrrggggggghhhhhh

Hi ethel,

Let me cite Nigel Garvey from this thread:

Hi,

AppleScript displays all integer values ≥ 2²â¹ in scientific notation.
As number it will be treated correctly in all math operations,
if you need it as a string, you have to coerce it to text with this subroutine

thx for the super quick response
Sexy routine - thanks muchly
hopefully that will make life easier
(needed to reference an object ID - the e number seemed to be screwing referencing)

It bothered me that the script didn’t work for negative exponents:

set xx to 8.123456789E-10
set yy to number_to_string(xx)
yy


on number_to_string(this_number)
	set this_number to this_number as string
	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
		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
			if x is not 0 then
				set the first_part to text 1 thru (x - 1) of this_number
			else
				set the first_part to ""
			end if
			set the second_part to text (x + 1) thru (z - 1) of this_number
			set the converted_number to the first_part & second_part
			set n to text (y + 1) thru -1 of this_number as number
			set zero to "0."
			
			if n > 1 then
				repeat (n - 1) times
					set zero to zero & "0"
				end repeat
			end if
			set converted_number to zero & converted_number
		else
			set converted_number to this_number
		end if
	end if
	
	return converted_number
end number_to_string


Nice, CWT :wink:

a perfectionist - nice scriptin
” unfortunately doesnt help my script
seems the returned object cant be converted to text to be corrected to be re-referenced as the corrected version


set Fiil to "Manuka:Users:dom:Desktop:118348_FLIN_recads_QpVer_Swed_hr.pdf" as string
tell application "FlightCheck Professional 6"
	new job Fiil

	set docList to every top level document of job
--tried everything i can think of here to fox the Object Reference of item 1 of docList
	set arse to (name of item 1 of docList) -- will sometimes error (when Flightcheck gives the random number that gets Exponeted)
end

I think you want:


set Fiil to "Manuka:Users:dom:Desktop:118348_FLIN_recads_QpVer_Swed_hr.pdf" as string
tell application "FlightCheck Professional 6"
	new job Fiil
	set docList to every top level document of job
	set arse_temp to (name of item 1 of docList) as text
	set arse to number_to_string(arse_temp)
end

Does that error on set arse_temp?

it errors on the ‘text’ - will not allow the coerce

What about this?

set Fiil to "Manuka:Users:dom:Desktop:118348_FLIN_recads_QpVer_Swed_hr.pdf" as string
tell application "FlightCheck Professional 6"
	new job Fiil
	set docList to every top level document of job
	set arse_temp to (name of item 1 of docList)
	set arse_temp to arse_temp as text
	set arse to number_to_string(arse_temp)
end tell

nope
i think it may be a prob with the ‘Flightcheck’ script support

If you’re calling a handler from within a ‘tell’ block, you have to put ‘my’ in front of the call to associate it with the script rather than with the application:

tell application "FlightCheck Professional 6"
	-- Blah blah blah.
	set arse to my number_to_string(arse_temp)
end tell

I don’t have the application involved, so I can’t check how you’ve scripted it. A ‘name’ is usually text anyway.

it doesnt get to the function call (had it correct in the real code, honest)

the error seems to be with trying to ‘touch’ the object returned from within Flightcheck
It seems the E number can not then be used to reference the object (even though it was given by Flightcheck)
i was attempting to get the E number (object reference) coerced to text so that i can then use that to hopefully reference the object
Flightcheck will not allow that coercion

Would this be a error/problem/limit within Flightchecks implementation of applescript?
or would it be applescript interfering when it shouldnt?

It’s difficult for someone who doesn’t have FlightCheck to guess what the problem may be; and you haven’t said exactly what error you’re getting.

To me, this looks a little suspect:

If the purpose of this is to create a new ‘job’ and then to get every ‘top level document’ of it, the conventional way would look like something like this:

tell application "FlightCheck Professional 6"
	set Fiil to (make new job at end of jobs)
	set docList to every top level document of Fiil

	-- You might be able to get the names like this:
	set nameList to name of every top level document of Fiil
	-- ...
end tell

If you run your script as shown in post #7 above, what do you see in Script Editor’s Result pane? If there’s no result, for instance, trying to coerce it to text would produce an error.

doesnt allow
set Fiil to (make new job at end of jobs)

also doesnt allow
set nameList to name of every top level document of job

(*FlightCheck Professional 6 got an error: Can't get name of every top level document of job.*)
(*-1728*)

is this flightchecks implementation/fault?

Implementation, I expect. It means that FlightCheck doesn’t know how to resolve that particular reference.

Not having FlightCheck myself, I don’t know how to resolve your script. I’m trying to feel my way to an understanding of whether the FlightCheck syntax is correct, whether ‘job’ is a FlightCheck element or the name of a variable, and what comes out when you try to get the ‘name’ of a ‘top level document’ held in a list. This last bit (‘arse_temp’ in cwtnospam’s last suggestion) is particularly useful for understanding why you get an error when you try to coerce it to text. You apparently have reason to think it’s a number. Is it an AppleScript number or a textual representation? On the other hand, one of your posts calls it an “object reference”. How is it represented in Script Editor’s Result pane? It would also be helpful to know what the returned error is.

My best theory at the moment, if the the first two FlightCheck statements are correct, is that there may be a problem resolving the reference ‘name of item 1 of docList’, which is part FlightCheck (the ‘name’ of a ‘top level document’) and part core AppleScript (item 1 of a list). If might help to split it into the individual components:

set Fiil to "Manuka:Users:dom:Desktop:118348_FLIN_recads_QpVer_Swed_hr.pdf"
tell application "FlightCheck Professional 6"
	new job Fiil
	set docList to every top level document of job
	set arse_doc to item 1 of docList
	set arse_temp to name of arse_doc
	set arse to my number_to_string(arse_temp)
end tell

Hello

The conversion handler works well . if the running system uses the decimal period. With systems using the decimal comma it fails :frowning:

Here is an enhanced version.

set xx to 8.123456789E-10
set yy to number_to_string(xx)
yy

on number_to_string(this_number)
	set this_number to this_number as string
	set deci to character 2 of (0.5 as text)
	set x to the offset of deci in this_number
	set z to the offset of "E" in this_number
	if this_number contains "E+" then
		set y to the offset of "+" 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
		if this_number contains "E-" then
			set y to the offset of "-" in this_number
			if x is not 0 then
				set the first_part to text 1 thru (x - 1) of this_number
			else
				set the first_part to ""
			end if
			set the second_part to text (x + 1) thru (z - 1) of this_number
			set the converted_number to the first_part & second_part
			set n to text (y + 1) thru -1 of this_number as number
			set zero to "0."
			
			if n > 1 then
				repeat (n - 1) times
					set zero to zero & "0"
				end repeat
			end if
			set converted_number to zero & converted_number
		else
			set converted_number to this_number
		end if
	end if
	
	return converted_number
end number_to_string


Yvan KOENIG (from FRANCE lundi 17 novembre 2008 18:41:52)

Maybe these days to convert from exponential to integer, this would work.


set converted_value to do shell script "printf \"%.0f\" 3.551232E+6"
log "converted_value"
log converted_value

I forgot this old thread.
If FlightCheck Professional 6 dislike the coerce to text instruction, maybe this edited version would be OK:

set Fiil to "Manuka:Users:dom:Desktop:118348_FLIN_recads_QpVer_Swed_hr.pdf" as string
tell application "FlightCheck Professional 6"
	new job Fiil
	set docList to every top level document of job
	set arse_temp to (name of item 1 of docList)
	tell me to set arse_temp to arse_temp as text # Now the coercion is asked to AppleScript
	set arse to my number_to_string(arse_temp) # added "my" just for safe
end tell

Yvan KOENIG (VALLAURIS, France) mardi 28 janvier 2014 18:52:07