#4 Presenting Large Numbers Attractively

A common mistake that programmers make is to present the results of calculations to the user without first formatting them. It's difficult for users to ascertain whether 43245435 goes into the millions without manually counting from right to left and mentally inserting a comma every three digits. Use this script to format your results.

The Code

 #!/bin/sh # nicenumber -- Given a number, shows it in comma-separated form. # Expects DD and TD to be instantiated. Instantiates nicenum # or, if a second arg is specified, the output is echoed to stdout. nicenumber() { # Note that we assume that '.' is the decimal separator in # the INPUT value to this script. The decimal separator in the output value is ...

Get Wicked Cool Shell Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.