Search guides and the APICtrl K
  1. API reference
  2. Data, text and crypto

number_text.h

Numbers in text, whatever the C locale says.

#include <sonore/number_text.h>
  • 4other declarations
On this page

Design notes

A plugin does not own its process. Hosts call setlocale() -- a German or a Spanish DAW sets LC_NUMERIC to a comma locale -- and from then on every printf("%g") in the plugin writes "0,5" and every strtod reads "0.5" as 0. In a JSON settings file that turns [0.5] into [0,5], two numbers; in an SVG it truncates every coordinate at the point; in a saved state it puts a knob back at zero. Nobody sees it on the developer's machine.

The fix is the one every portable parser uses: format with the C library, which rounds correctly, then turn the locale's decimal point into '.'; and parse by turning '.' into the locale's decimal point first. The library does the arithmetic -- exactly, which a hand-written digit loop does not -- and only the one character that varies is translated.

Functions 4

↑↓ to move↵ to openEvery public name in the headers, and every guide