Help us shape the future of Go! Take the 2026 Go Developer Survey

decimalfmt

package
v1.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package decimalfmt renders Arrow decimal128 values as exact fixed-point strings, shared by the Thrift (arrowbased) and kernel result paths so a DECIMAL renders identically regardless of backend. Keeping one implementation means a precision fix (e.g. databricks-sql-go#274) lands in both at once.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(dst []byte, n decimal128.Num, scale int32) []byte

Append renders n at the given scale into dst and returns the extended slice, exactly as ExactString would but without forcing a string allocation — for callers that render many decimals into a reused buffer (e.g. a batch-scoped arena). The output is byte-for-byte identical to ExactString.

The magnitude is rendered from the unscaled integer with no heap allocation when it fits in a uint64 (the common case: |unscaled| < 2^64 covers every DECIMAL(≤18) and every DECIMAL(≤38) value whose magnitude stays under 2^64). A true 128-bit magnitude (DECIMAL(20+) with a very large value) falls back to math/big, matching the old renderer's output exactly.

func ExactString

func ExactString(n decimal128.Num, scale int32) string

ExactString renders an Arrow decimal128 as an exact fixed-point string, applying scale by digit placement rather than float conversion. This preserves precision a float64 would lose beyond ~17 significant digits (databricks-sql-go#274). A negative scale is not produced by the server and is treated as scale 0 rather than panicking.

It allocates only the returned string (the digit rendering uses a stack scratch, no math/big for magnitudes that fit in a uint64 — i.e. every DECIMAL(≤18) and most DECIMAL(≤38) values). See Append for the zero-copy form.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL