v
v copied to clipboard
strconv: number formatting. new pullrequest trying to pass the checks.
This contribution adds the possibility to format numbers (integers, floats) with thousands separators and with a custom-set radix.
// f32_format - Formats an f32-number as a string by adding thousands-separators and a custom-set radix. The first argument represents the number you want to format, the second represents the thousands-separator as a string and the third represents the radix also as a string.
Example:
assert strings.f32_format(1000.48, ",", ".") == "1,000.48"
// f64_format - Formats an f64-number as a string by adding thousands-separators and a custom-set radix. The first argument represents the number you want to format, the second represents the thousands-separator as a string and the third represents the radix also as a string.
Example:
assert strings.f64_format(10000.4567657657, ",", ".") == "10,000.4567657657"
// int_format - Formats an integer (i16 or i32 or i64) by adding thousands-separators and returns a string. The first argument represents the integer you want to format, the second represents the thousands-separator as a string.
Example:
assert strings.int_format(1000000, ",") == "1,000,000"
// uint_format - Formats an unsigned integer (u16 or u32 or u64) by adding thousands-separators and returns a string. The first argument represents the integer you want to format, the second represents the thousands-separator as a string.
Example:
assert strings.uint_format(1000000, ",") == "1,000,000"
One of the errors is just that you need to run v fmt -w vlib/strconv/number_formatting.v
Any chance this can be fixed up soon? There's a new feature that will help the formatting - just add // vfmt off
before the arrays, and // vfmt on
after.
You could just add those at the top & bottom of the file, but please don't... just around the arrays.