¿Cómo evito que AppleScript use números cortos?

Entonces AppleScript por defecto usa la notación exponencial de números - por ejemplo, 2.99E+68. ¿Cómo evito que eso suceda? Quiero el número escrito como está.

Respuestas (2)

convertNumberToStringApple proporciona una función AppleScript .

Guía de secuencias de comandos de automatización de Mac: manipulación de números

Convertir un número largo en una cadena

En AppleScript, los valores numéricos largos se muestran en notación científica. Por ejemplo, 1234000000un script lo muestra como 1.234E+9. Cuando este valor se coacciona a una cadena, se convierte en: "1.234E+9". El controlador del Listado 20-3 convierte un número, independientemente de su longitud, en una cadena de caracteres numéricos en lugar de una cadena numérica en notación científica.

on convertNumberToString(theNumber)
    set theNumberString to theNumber as string
    set theOffset to offset of "E" in theNumberString
    if theOffset = 0 then return theNumberString
    set thePrefix to text 1 thru (theOffset - 1) of theNumberString
    set theConvertedNumberPrefix to ""
    if thePrefix begins with "-" then
        set theConvertedNumberPrefix to "-"
        if thePrefix = "-" then
            set thePrefix to ""
        else
            set thePrefix to text 2 thru -1 of thePrefix
        end if
    end if
    set theDecimalAdjustment to (text (theOffset + 1) thru -1 of theNumberString) as number
    set isNegativeDecimalAdjustment to theDecimalAdjustment is less than 0
    if isNegativeDecimalAdjustment then
        set thePrefix to (reverse of (characters of thePrefix)) as string
        set theDecimalAdjustment to -theDecimalAdjustment
    end if
    set theDecimalOffset to offset of "." in thePrefix
    if theDecimalOffset = 0 then
        set theFirstPart to ""
    else
        set theFirstPart to text 1 thru (theDecimalOffset - 1) of thePrefix
    end if
    set theSecondPart to text (theDecimalOffset + 1) thru -1 of thePrefix
    set theConvertedNumber to theFirstPart
    set theRepeatCount to theDecimalAdjustment
    if (length of theSecondPart) is greater than theRepeatCount then set theRepeatCount to length of theSecondPart
    repeat with a from 1 to theRepeatCount
        try
            set theConvertedNumber to theConvertedNumber & character a of theSecondPart
        on error
            set theConvertedNumber to theConvertedNumber & "0"
        end try
        if a = theDecimalAdjustment and a is not equal to (length of theSecondPart) then set theConvertedNumber to theConvertedNumber & "."
    end repeat     if theConvertedNumber ends with "." then set theConvertedNumber to theConvertedNumber & "0"
    if isNegativeDecimalAdjustment then set theConvertedNumber to (reverse of (characters of theConvertedNumber)) as string
    return theConvertedNumberPrefix & theConvertedNumber
end convertNumberToString
solo para estar seguro, ¿funcionará incluso cuando necesite trabajar con él como un número después?
@Prokop Si desea trabajar con él como un número, simplemente manténgalo como el número original y trabaje con eso hasta que desee generarlo como una cadena.
Bien, gracias. ¿Le importaría revisar mi otra pregunta sin respuesta también?

Puede forzar el número a una unidad de medida y luego a una cadena, como esta:

1.2345E+9 as inches as string

que regresará "1234500000".

Puede utilizar cualquier unidad de medida, como kilogramos, centímetros cúbicos, galones, grados Kelvin, etc.