Multiple precision decimal numbers for use by the `strconv` package. NOTE: This is only for floating point printing and nothing else.

Collection Info

View Source
Collection
core
Path
strconv/decimal
Entries
14

Source Files

Types

1

Procedures

13

assign #

Source
assign :: proc(a: ^Decimal, idx: u64) {…}

Converts a given u64 integer `idx` to its Decimal representation in the provided Decimal struct. **Used for internal Decimal Operations.** **Inputs** - a: Where the result will be stored - idx: The value to be assigned to the Decimal

can_round_up #

Source
can_round_up :: proc(a: ^Decimal, nd: int) -> bool {…}

Determines if the Decimal can be rounded up at the given digit index **Inputs** - a: The Decimal to check - nd: The digit index to consider for rounding up **Returns** Boolean if can be rounded up at the given index (>=5)

decimal_to_string #

Source
decimal_to_string :: proc(buf: []u8, a: ^Decimal) -> string {…}

Converts a Decimal to a string representation, using the provided buffer as storage. **Inputs** - buf: A byte slice buffer to hold the resulting string - a: The struct to be converted to a string **Returns** - A string representation of the Decimal

round #

Source
round :: proc(a: ^Decimal, nd: int) {…}

Rounds the Decimal at the given digit index **Inputs** - a: The Decimal to be modified - nd: The digit index to round

round_down #

Source
round_down :: proc(a: ^Decimal, nd: int) {…}

Rounds down the decimal value to the specified number of decimal places **Inputs** - a: The Decimal value to be rounded down - nd: The number of decimal places to round down to Example: import "core:fmt" import "core:strconv/decimal" round_down_example :: proc() { d: decimal.Decimal str := [64]u8{} ok := decimal.set(&d, "123.456") decimal.round_down(&d, 5) fmt.println(decimal.decimal_to_string(str[:], &d)) } Output: 123.45

round_up #

Source
round_up :: proc(a: ^Decimal, nd: int) {…}

Rounds the Decimal up at the given digit index **Inputs** - a: The Decimal to be modified - nd: The digit index to round up

rounded_integer #

Source
rounded_integer :: proc(a: ^Decimal) -> u64 {…}

Extracts the rounded integer part of a decimal value **Inputs** - a: A pointer to the Decimal value to extract the rounded integer part from WARNING: There are no guarantees about overflow. **Returns** The rounded integer part of the input decimal value Example: import "core:fmt" import "core:strconv/decimal" rounded_integer_example :: proc() { d: decimal.Decimal ok := decimal.set(&d, "123.456") fmt.println(decimal.rounded_integer(&d)) } Output: 123

set #

Source
set :: proc(d: ^Decimal, s: string) -> (ok: bool) {…}

Sets a Decimal from a given string `s`. The string is expected to represent a float. Stores parsed number in the given Decimal structure. If parsing fails, the Decimal will be left in an undefined state. **Inputs** - d: Pointer to a Decimal struct where the parsed result will be stored - s: The input string representing the floating-point number **Returns** - ok: A boolean indicating whether the parsing was successful

shift #

Source
shift :: proc(a: ^Decimal, i: int) {…}

Shifts the decimal of the input value by the specified number of places **Inputs** - a: The Decimal to be modified - i: The number of places to shift the decimal (positive for left shift, negative for right shift)

shift_left #

Source
shift_left :: proc(a: ^Decimal, k: uint) {…}

Shifts the decimal of the input value to the left by `k` places WARNING: asserts `k < 61` **Inputs** - a: The Decimal to be modified - k: The number of places to shift the decimal to the left

shift_right #

Source
shift_right :: proc(a: ^Decimal, k: uint) {…}

Shifts the Decimal value to the right by k positions. **Used for internal Decimal Operations.** **Inputs** - a: The Decimal struct to be shifted - k: The number of positions to shift right

trim #

Source
trim :: proc(a: ^Decimal) {…}

Trims trailing zeros in the given Decimal, updating the count and decimal_point values as needed. **Inputs** - a: Pointer to the Decimal struct to be trimmed