Submission + - Is there a "standard" way of formatting a number ? 8
Pieroxy writes: I recently created a small open source project to monitor one's computer "essential" metrics: Conkw.
As I was writing it I had to come up with a way for users to format a number. I needed a small string the user could write to describe exactly what they want to do with their number. Some examples can be: write it as a 3-digit number suffixed by SI prefixes when the numbers are too big or too small, display a timestamp as HH:MM string, or just the day of week, eventually cut to the first three characters, do the same with a timestamp in milliseconds, or nanoseconds, display a nice string out of a number of seconds to express a duration ("3h 12mn 17s"), pad the number with spaces so that all numbers are aligned (left or right), force a fixed number of digits after the decimal point, etc.
In other words, I was looking for a "universal" way of formatting numbers and failed to find any kind of standard online. Do Slashdot readers know of such a thing or should I create my own?
As I was writing it I had to come up with a way for users to format a number. I needed a small string the user could write to describe exactly what they want to do with their number. Some examples can be: write it as a 3-digit number suffixed by SI prefixes when the numbers are too big or too small, display a timestamp as HH:MM string, or just the day of week, eventually cut to the first three characters, do the same with a timestamp in milliseconds, or nanoseconds, display a nice string out of a number of seconds to express a duration ("3h 12mn 17s"), pad the number with spaces so that all numbers are aligned (left or right), force a fixed number of digits after the decimal point, etc.
In other words, I was looking for a "universal" way of formatting numbers and failed to find any kind of standard online. Do Slashdot readers know of such a thing or should I create my own?