Loading...
Searching...
No Matches
number_format.c File Reference

Pure number and string formatting, no SDK behind it. More...

#include "text/number_format.h"
#include "text/cstring_fit.h"
#include <stdio.h>
#include <string.h>

Functions

static unsigned int magnitude_of (int value)
 The size of a number without its sign, as an unsigned value.
void number_group (char *buffer, size_t size, int value)
 Format an integer with apostrophe thousands separators (e.g. 20358 -> "20'358").
void fmt_int_or_dash (char *buffer, size_t size, int value, const char *fmt)
 Format an integer, or "--" when there is no reading yet.
void fmt_hundredths (char *buffer, size_t size, int value)
 Format hundredths as a two-decimal number, e.g. 26174 -> "261.74".
void fmt_pct_signed (char *buffer, size_t size, int value)
 Format hundredths as a signed two-decimal percent, e.g. 125 -> "+1.25%".
void copy_bounded (char *dst, uint8_t cap, const uint8_t *src, uint8_t len)
 Copy bytes into a fixed buffer, taking what fits and terminating it.
bool cstring_is_clean (const char *s, uint16_t size)
 Whether a byte range holds a string worth keeping.
bool cstring_setting_is_clean (const char *s, uint16_t size, const char *default_str)
 Whether a saved text setting reads as one, where an empty setting can be the real value.

Detailed Description

Pure number and string formatting, no SDK behind it.

Function Documentation

◆ magnitude_of()

unsigned int magnitude_of ( int value)
static

The size of a number without its sign, as an unsigned value.

abs() on INT_MIN has no answer that fits an int, and the stock price comes straight off the wire. Doing the negation in unsigned maths gives the right size for every int, INT_MIN included.

Parameters
valueThe number to take the size of.
Returns
The value with its sign dropped.