Re: Sequences and long files
- Posted by Robert B Pilkington <bpilkington at JUNO.COM> May 08, 1998
- 683 views
>>puts( fn, "{" ) >>for whatever = 1 to NumberOfRecords do >> puts( fn, "{" ) >> for count = 1 to length( record ) do >> data = record[count] >> if sequence( data ) then >> printf( fn, "\"%s\"", data ) >> else >> printf( fn, "%d", data ) >> end if >> if count != length( record ) then >> puts( fn, "," ) >> end if >> end for >> puts( fn, "}" ) >>if whatever != NumberOfRecords then >> puts( fn, "," ) >>end if >>end for >>puts( fn, "}" ) > >If you use the %d to print numbers, you'll lose the decimals. >You can use %f to save the number accurately (more or less), >but that takes a lot of space. If there are more numbers than >strings in your data, it will take MORE space than the native format. >Arrgh! Untested, but should work, and if it doesn't, you get the idea: if sequence( data ) then -- Print sequence printf( fn, "\"%s\"", data ) elsif integer(data) then -- Print integer number printf( fn, "%d", data ) else -- Handle float. -- Assuming .16 is the best decimal precision num_string = sprintf("%.16f", data) -- Search for the first character that isn't a zero for i = length(num_string) to find('.', num_string) by -1 do if num_string[i] != '0' then -- Okay, we have the total precision, convert to sequence num_string = sprintf("%d", i-find('.', num_string)) exit end if end for -- Use the num_string sequence to cut down on space used: printf( fn, "%." & num_string & "f", data ) end if _____________________________________________________________________ You don't need to buy Internet access to use free Internet e-mail. Get completely free e-mail from Juno at http://www.juno.com Or call Juno at (800) 654-JUNO [654-5866]