Skip to main content
Brian Leach
Participating Frequently
Jun 6, 2025 4:46 AM UTC
Question

UDO Formatting large numbers

Wise ones,

Is there a way to prevent UDOWrite converting large numbers into scientific format?

For example:

PROGRAM temp

$INCLUDE UNIVERSE.INCLUDE UDO.H

Value = 1234567890.123
Ok = UDOCreate(UDO_OBJECT,hObject)
Ok = UDOSetProperty(hObject,'large', Value)
Ok = UDOWrite(hObject, UDOFORMAT_JSON, JSON)
Crt JSON

STOP

{
        "large":        1.234568e+09
}

I can't make it a string as that will fail the JSON schema validation.

Integral numbers are not affected by this so I could INT() it, but that's not really a solution.

Thanks

    3 replies

    Mike Rajkowski
    Rocketeer
    Jun 6, 2025 10:49 AM UTC

    Wise ones,

    Is there a way to prevent UDOWrite converting large numbers into scientific format?

    For example:

    PROGRAM temp

    $INCLUDE UNIVERSE.INCLUDE UDO.H

    Value = 1234567890.123
    Ok = UDOCreate(UDO_OBJECT,hObject)
    Ok = UDOSetProperty(hObject,'large', Value)
    Ok = UDOWrite(hObject, UDOFORMAT_JSON, JSON)
    Crt JSON

    STOP

    {
            "large":        1.234568e+09
    }

    I can't make it a string as that will fail the JSON schema validation.

    Integral numbers are not affected by this so I could INT() it, but that's not really a solution.

    Thanks

    Brian,

    Yes,  there was a fix a while back to handle the large numbers, but that was related to large integers, and I understand why that would not work for you.

    While I can think of some options post creation of JSON, that would come with its own issues and overhead.

    I suggest you open a support ticket.  

    Henry Unger
    Participating Frequently
    Jun 6, 2025 1:37 PM UTC

    Wise ones,

    Is there a way to prevent UDOWrite converting large numbers into scientific format?

    For example:

    PROGRAM temp

    $INCLUDE UNIVERSE.INCLUDE UDO.H

    Value = 1234567890.123
    Ok = UDOCreate(UDO_OBJECT,hObject)
    Ok = UDOSetProperty(hObject,'large', Value)
    Ok = UDOWrite(hObject, UDOFORMAT_JSON, JSON)
    Crt JSON

    STOP

    {
            "large":        1.234568e+09
    }

    I can't make it a string as that will fail the JSON schema validation.

    Integral numbers are not affected by this so I could INT() it, but that's not really a solution.

    Thanks

    Regardless of the conversion to scientific notation, something is very wrong because it is losing precision.

    Doug Averch
    Inspiring
    Jun 6, 2025 3:06 PM UTC

    Wise ones,

    Is there a way to prevent UDOWrite converting large numbers into scientific format?

    For example:

    PROGRAM temp

    $INCLUDE UNIVERSE.INCLUDE UDO.H

    Value = 1234567890.123
    Ok = UDOCreate(UDO_OBJECT,hObject)
    Ok = UDOSetProperty(hObject,'large', Value)
    Ok = UDOWrite(hObject, UDOFORMAT_JSON, JSON)
    Crt JSON

    STOP

    {
            "large":        1.234568e+09
    }

    I can't make it a string as that will fail the JSON schema validation.

    Integral numbers are not affected by this so I could INT() it, but that's not really a solution.

    Thanks

    Since UDO does not fully support JSON types, I make everything a string and covert it into JavaScript 

    $INCLUDE UNIVERSE.INCLUDE UDO.H

    Value = "1234567890.123"

    Ok = UDOCreate(UDO_OBJECT,hObject)

    Ok = UDOSetProperty(hObject,'large', Value)

    Ok = UDOWrite(hObject, UDOFORMAT_JSON, JSON)

    Crt JSON

    STOP

    >RUN BP DOUG11
    {
    "large": "1234567890.123"
    }
    Last auto-saved at: 06-06-2025 15:09
    Doug Averch Owner https://www.u2logic.com/