v icon indicating copy to clipboard operation
v copied to clipboard

strconv: number formatting. new pullrequest trying to pass the checks.

Open floscodes opened this issue 2 years ago • 2 comments

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"

floscodes avatar Sep 26 '22 17:09 floscodes

One of the errors is just that you need to run v fmt -w vlib/strconv/number_formatting.v

JalonSolov avatar Sep 28 '22 17:09 JalonSolov

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.

JalonSolov avatar Dec 17 '22 02:12 JalonSolov