Skip to content

API CSng en

Codex edited this page Sep 23, 2026 · 1 revision

CSng

ClassicUO / Basic IDE

Home · API · Basic

Reads a numeric setting for calculations, for example a delay expressed in seconds.

Exact syntax

CSng(value:Any) -> Decimal

Parameters

  • value — One required Integer/Decimal or numeric String. Text uses a dot and optional exponent, independent of UI language; "0x0EED" is not numeric text here. Invalid text, Array, Object and Unit become 0. Validate user input with IsNumeric before converting.

Returns

Decimal backed by a 64-bit double. CDbl and CSng use the same conversion and precision; CSng does not reduce the value to a 32-bit Single. Invalid input becomes 0, so 0 alone cannot tell you whether parsing succeeded. NaN and Infinity can be returned; validate the allowed range separately.

Behavior

  • One required Integer/Decimal or numeric String. Text uses a dot and optional exponent, independent of UI language; "0x0EED" is not numeric text here. Invalid text, Array, Object and Unit become 0. Validate user input with IsNumeric before converting.
  • Decimal backed by a 64-bit double. CDbl and CSng use the same conversion and precision; CSng does not reduce the value to a 32-bit Single. Invalid input becomes 0, so 0 alone cannot tell you whether parsing succeeded. NaN and Infinity can be returned; validate the allowed range separately.

Internal functions: from call to result

Reads a numeric setting for calculations, for example a delay expressed in seconds.

1. BasicDouble

One required Integer/Decimal or numeric String. Text uses a dot and optional exponent, independent of UI language; "0x0EED" is not numeric text here. Invalid text, Array, Object and Unit become 0. Validate user input with IsNumeric before converting.

Decimal backed by a 64-bit double. CDbl and CSng use the same conversion and precision; CSng does not reduce the value to a 32-bit Single. Invalid input becomes 0, so 0 alone cannot tell you whether parsing succeeded. NaN and Infinity can be returned; validate the allowed range separately.

Project source: external/InjectionScript/src/InjectionScript/Runtime/InjectionApi.cs; function BasicDouble.

Examples

CSng — 1

# CSng1
#
# Reads a numeric setting for calculations, for example a delay expressed in seconds.
#
# Decimal backed by a 64-bit double. CDbl and CSng use the same conversion and precision; CSng
# does not reduce the value to a 32-bit Single. Invalid input becomes 0, so 0 alone cannot tell
# you whether parsing succeeded. NaN and Infinity can be returned; validate the allowed range
# separately.

SUB Main()
    # value="0.35" is text with a decimal point. Main returns Decimal 0.35 seconds; no waiting
    # occurs.

    RETURN CSng("0.35")
END SUB

Parameter and execution notes:

  • value="0.35" is text with a decimal point. Main returns Decimal 0.35 seconds; no waiting occurs.

CSng — 2

# CSng2
#
# Reads a numeric setting for calculations, for example a delay expressed in seconds.
#
# Decimal backed by a 64-bit double. CDbl and CSng use the same conversion and precision; CSng
# does not reduce the value to a 32-bit Single. Invalid input becomes 0, so 0 alone cannot tell
# you whether parsing succeeded. NaN and Infinity can be returned; validate the allowed range
# separately.

SUB Main()
    # value="3e1" means 30. Dividing by 4 produces Decimal 7.5. Exponent notation is accepted
    # independently of the interface language.

    VAR total = CSng("3e1")
    RETURN total / 4
END SUB

Parameter and execution notes:

  • value="3e1" means 30. Dividing by 4 produces Decimal 7.5. Exponent notation is accepted independently of the interface language.

CSng — 3

# CSng3
#
# Reads a numeric setting for calculations, for example a delay expressed in seconds.
#
# Decimal backed by a 64-bit double. CDbl and CSng use the same conversion and precision; CSng
# does not reduce the value to a 32-bit Single. Invalid input becomes 0, so 0 alone cannot tell
# you whether parsing succeeded. NaN and Infinity can be returned; validate the allowed range
# separately.

SUB Main()
    # Milliseconds receives secondsText="0.35". It rejects nonnumeric text, NaN and values outside
    # 0.1..5 seconds with -1. Otherwise it multiplies by 1000 and returns Decimal 350, suitable for
    # a later wait. It does not call Wait itself.

    RETURN Milliseconds("0.35")
END SUB

SUB Milliseconds(secondsText)
    IF NOT IsNumeric(secondsText) THEN
        RETURN -1
    END IF
    VAR seconds = CSng(secondsText)
    IF CStr(seconds) = "NaN" OR seconds < 0.1 OR seconds > 5 THEN
        RETURN -1
    END IF
    RETURN seconds * 1000
END SUB

Parameter and execution notes:

  • Milliseconds receives secondsText="0.35". It rejects nonnumeric text, NaN and values outside 0.1..5 seconds with -1. Otherwise it multiplies by 1000 and returns Decimal 350, suitable for a later wait. It does not call Wait itself.

Русский · English · Українська · Français · Deutsch · Italiano · Español · 繁體中文 · 日本語 · 한국어

Clone this wiki locally