I have a value that is being calculated that at a certain point is a float value.
If I do this
display dialog myNumber
-- at this time I see myNumber as 200.3
I see the number perfectly with one decimal place but then I write the number to a file using this
set line to ("point = (" & myNumber & ")" & linefeed)
my write_to_file(line, myFile, true)
-- the number is written as 2 instead of 200.3
this is the code to write to the file
on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
the problem is this: when I see the text file, that number that is 200.3 is transformed in 2
On my French system, the script behave flawlessly except the fact that line is not accepted as a varname.
I just replaced it by a_line.
# instruction replacing your code calculating the value to store
set myNumber to 2003 / 10
# builds a fake file path
set myFile to (path to desktop as text) & "beurk.txt"
log myNumber # added to check the passed value.
set a_line to "point = (" & myNumber & ")" & linefeed
my write_to_file(a_line, myFile, true)
-- the number is written as 2 instead of 200.3
on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
It would be a good idea to double check the code building the value passed by the variable myNumber.
The log instruction is added to check what is really passed to the code.