Skip to content

API Round en

Codex edited this page Sep 23, 2026 · 1 revision

Round

ClassicUO / Basic IDE

Home · API · Basic

Rounds a calculated value to a chosen number of decimal places, for example a displayed resource percentage.

Exact syntax

Round(number:Any, digits:Any) -> Decimal
Round(value:Any) -> Any

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.
  • number — 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.
  • digits — Optional Integer decimal-place count; omitted means 0. Values below 0 are clamped to 0 and values above 15 to 15. This argument does not select rounding to tens or hundreds.

Returns

Decimal, using midpoint-to-even rounding: Round(2.5) is 2 and Round(3.5) is 4. Unlike CInt/CLng, exact halves are not rounded away from zero. Binary floating-point representation can affect apparent decimal ties; the result is a number, not fixed-width formatted text.

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, using midpoint-to-even rounding: Round(2.5) is 2 and Round(3.5) is 4. Unlike CInt/CLng, exact halves are not rounded away from zero. Binary floating-point representation can affect apparent decimal ties; the result is a number, not fixed-width formatted text.

Internal functions: from call to result

Rounds a calculated value to a chosen number of decimal places, for example a displayed resource percentage.

1. BasicRound

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, using midpoint-to-even rounding: Round(2.5) is 2 and Round(3.5) is 4. Unlike CInt/CLng, exact halves are not rounded away from zero. Binary floating-point representation can affect apparent decimal ties; the result is a number, not fixed-width formatted text.

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

Examples

Round — 1

# Round1
#
# Rounds a calculated value to a chosen number of decimal places, for example a displayed
# resource percentage.
#
# Decimal, using midpoint-to-even rounding: Round(2.5) is 2 and Round(3.5) is 4. Unlike
# CInt/CLng, exact halves are not rounded away from zero. Binary floating-point representation
# can affect apparent decimal ties; the result is a number, not fixed-width formatted text.

SUB Main()
    # With one argument, Round(2.5) rounds to zero decimal places and returns Decimal 2. CInt(2.5)
    # would return Integer 3 in this engine.

    RETURN Round(2.5)
END SUB

Parameter and execution notes:

  • With one argument, Round(2.5) rounds to zero decimal places and returns Decimal 2. CInt(2.5) would return Integer 3 in this engine.

Round — 2

# Round2
#
# Rounds a calculated value to a chosen number of decimal places, for example a displayed
# resource percentage.
#
# Decimal, using midpoint-to-even rounding: Round(2.5) is 2 and Round(3.5) is 4. Unlike
# CInt/CLng, exact halves are not rounded away from zero. Binary floating-point representation
# can affect apparent decimal ties; the result is a number, not fixed-width formatted text.

SUB Main()
    # number=12.375, digits=2 gives Decimal 12.38. digits describes decimal places, not significant
    # digits.

    RETURN Round(12.375,2)
END SUB

Parameter and execution notes:

  • number=12.375, digits=2 gives Decimal 12.38. digits describes decimal places, not significant digits.

Round — 3

# Round3
#
# Rounds a calculated value to a chosen number of decimal places, for example a displayed
# resource percentage.
#
# Decimal, using midpoint-to-even rounding: Round(2.5) is 2 and Round(3.5) is 4. Unlike
# CInt/CLng, exact halves are not rounded away from zero. Binary floating-point representation
# can affect apparent decimal ties; the result is a number, not fixed-width formatted text.

SUB Main()
    # Percent receives current=37, maximum=80, computes 46.25 and rounds to one decimal place:
    # Decimal 46.2. A nonpositive maximum returns -1 instead of dividing by zero. Supply already
    # validated finite resource values.

    RETURN Percent(37,80)
END SUB

SUB Percent(current,maximum)
    IF maximum <= 0 THEN
        RETURN -1
    END IF
    RETURN Round(CDbl(current) * 100 / maximum,1)
END SUB

Parameter and execution notes:

  • Percent receives current=37, maximum=80, computes 46.25 and rounds to one decimal place: Decimal 46.2. A nonpositive maximum returns -1 instead of dividing by zero. Supply already validated finite resource values.

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

Clone this wiki locally