ChartValueFormatters

Standard ChartValueFormatter factories.

Finite values are rounded half away from zero using the decimal representation returned by abs(value).toString(), not the exact binary fraction. Scientific notation is expanded, and negative zero is suppressed. Nonfinite values are displayed as NaN, Infinity, and -Infinity.

This assumes the platform's Double string uses decimal digits, an optional dot, and an optional e/E exponent. Last-digit differences between platform string representations can affect rounding at a boundary.

Properties

Link copied to clipboard

Rounds to two decimal places, then trims trailing zeros while keeping .0 for integers, including zero. For example: 3.0, 41.7, and 0.0.

Functions

Link copied to clipboard
fun fixed(precision: Int): ChartValueFormatter

Rounds and pads finite values to exactly precision decimal places, with no decimal point when precision is zero. Precision must be in 0..15.

Link copied to clipboard

Formats a value with the given prefix prepended, e.g. prefix("?").

Link copied to clipboard

Formats a value with the given suffix appended, e.g. suffix("%").