Deleted Added
full compact
humanize_number.3 (129733) humanize_number.3 (131759)
1.\" $NetBSD: humanize_number.3,v 1.4 2003/04/16 13:34:37 wiz Exp $
1.\" $NetBSD: humanize_number.3,v 1.4 2003/04/16 13:34:37 wiz Exp $
2.\" $FreeBSD: head/lib/libutil/humanize_number.3 129733 2004-05-25 20:11:50Z pjd $
2.\" $FreeBSD: head/lib/libutil/humanize_number.3 131759 2004-07-07 20:25:54Z ru $
3.\"
4.\" Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to The NetBSD Foundation
8.\" by Luke Mewburn and by Tomas Svensson.
9.\"
10.\" Redistribution and use in source and binary forms, with or without

--- 30 unchanged lines hidden (view full) ---

41.Sh NAME
42.Nm humanize_number
43.Nd format a number into a human readable form
44.Sh LIBRARY
45.Lb libutil
46.Sh SYNOPSIS
47.In libutil.h
48.Ft int
3.\"
4.\" Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to The NetBSD Foundation
8.\" by Luke Mewburn and by Tomas Svensson.
9.\"
10.\" Redistribution and use in source and binary forms, with or without

--- 30 unchanged lines hidden (view full) ---

41.Sh NAME
42.Nm humanize_number
43.Nd format a number into a human readable form
44.Sh LIBRARY
45.Lb libutil
46.Sh SYNOPSIS
47.In libutil.h
48.Ft int
49.Fn humanize_number "char *buf" "size_t len" "int64_t number" "const char *suffix" "int scale" "int flags"
49.Fo humanize_number
50.Fa "char *buf" "size_t len" "int64_t number" "const char *suffix"
51.Fa "int scale" "int flags"
52.Fc
50.Sh DESCRIPTION
51The
52.Fn humanize_number
53.Sh DESCRIPTION
54The
55.Fn humanize_number
53function formats the signed 64 bit quantity given in
56function formats the signed 64-bit quantity given in
54.Fa number
55into
56.Fa buffer .
57A space and then
58.Fa suffix
59is appended to the end.
57.Fa number
58into
59.Fa buffer .
60A space and then
61.Fa suffix
62is appended to the end.
63The buffer pointed to by
60.Fa buffer
61must be at least
62.Fa len
63bytes bytes long.
64.Pp
65If the formatted number (including
66.Fa suffix )
67would be too long to fit into
68.Fa buffer ,
69then divide
70.Fa number
71by 1024 until it will.
72In this case, prefix
73.Fa suffix
74with the appropriate SI designator.
75.Pp
76The prefixes are:
77.Bl -column "Prefix" "Description" "Multiplier" -offset indent
78.It Sy "Prefix" Ta Sy "Description" Ta Sy "Multiplier"
64.Fa buffer
65must be at least
66.Fa len
67bytes bytes long.
68.Pp
69If the formatted number (including
70.Fa suffix )
71would be too long to fit into
72.Fa buffer ,
73then divide
74.Fa number
75by 1024 until it will.
76In this case, prefix
77.Fa suffix
78with the appropriate SI designator.
79.Pp
80The prefixes are:
81.Bl -column "Prefix" "Description" "Multiplier" -offset indent
82.It Sy "Prefix" Ta Sy "Description" Ta Sy "Multiplier"
79.It k kilo 1024
80.It M mega 1048576
81.It G giga 1073741824
82.It T tera 1099511627776
83.It P peta 1125899906842624
84.It E exa 1152921504606846976
83.It Li k Ta No kilo Ta 1024
84.It Li M Ta No mega Ta 1048576
85.It Li G Ta No giga Ta 1073741824
86.It Li T Ta No tera Ta 1099511627776
87.It Li P Ta No peta Ta 1125899906842624
88.It Li E Ta No exa Ta 1152921504606846976
85.El
86.Pp
87The
88.Fa len
89argument must be at least 4 plus the length of
90.Fa suffix ,
91in order to ensure a useful result is generated into
92.Fa buffer .
93To use a specific prefix, specify this as
94.Fa scale
89.El
90.Pp
91The
92.Fa len
93argument must be at least 4 plus the length of
94.Fa suffix ,
95in order to ensure a useful result is generated into
96.Fa buffer .
97To use a specific prefix, specify this as
98.Fa scale
95(Multiplier = 1024 ^ scale).
96This can not be combined with any of the
99(multiplier = 1024 ^ scale).
100This cannot be combined with any of the
97.Fa scale
98flags below.
99.Pp
100The following flags may be passed in
101.Fa scale
102flags below.
103.Pp
104The following flags may be passed in
101.Pa scale :
102.Bl -tag -width Dv -offset indent
105.Fa scale :
106.Bl -tag -width ".Dv HN_DIVISOR_1000" -offset indent
103.It Dv HN_AUTOSCALE
104Format the buffer using the lowest multiplier possible.
105.It Dv HN_GETSCALE
106Return the prefix index number (the number of times
107.Fa number
108must be divided to fit) instead of formatting it to the buffer.
109.El
110.Pp
111The following flags may be passed in
107.It Dv HN_AUTOSCALE
108Format the buffer using the lowest multiplier possible.
109.It Dv HN_GETSCALE
110Return the prefix index number (the number of times
111.Fa number
112must be divided to fit) instead of formatting it to the buffer.
113.El
114.Pp
115The following flags may be passed in
112.Pa flags :
113.Bl -tag -width Dv -offset indent
116.Fa flags :
117.Bl -tag -width ".Dv HN_DIVISOR_1000" -offset indent
114.It Dv HN_DECIMAL
115If the final result is less than 10, display it using one digit.
116.It Dv HN_NOSPACE
117Do not put a space between
118.Fa number
119and the prefix.
120.It Dv HN_B
118.It Dv HN_DECIMAL
119If the final result is less than 10, display it using one digit.
120.It Dv HN_NOSPACE
121Do not put a space between
122.Fa number
123and the prefix.
124.It Dv HN_B
121Use 'B' (bytes) as prefix if the original result does not have a prefix.
125Use
126.Ql B
127(bytes) as prefix if the original result does not have a prefix.
122.It Dv HN_DIVISOR_1000
123Divide
124.Fa number
125with 1000 instead of 1024.
126.El
127.Sh RETURN VALUES
128The
129.Fn humanize_number
130function returns the number of characters stored in
131.Fa buffer
128.It Dv HN_DIVISOR_1000
129Divide
130.Fa number
131with 1000 instead of 1024.
132.El
133.Sh RETURN VALUES
134The
135.Fn humanize_number
136function returns the number of characters stored in
137.Fa buffer
132(excluding the terminating NUL) upon success, or \-1 upon failure.
138(excluding the terminating
139.Dv NUL )
140upon success, or \-1 upon failure.
133If
134.Dv HN_GETSCALE
135is specified, the prefix index number will be returned instead.
136.Sh SEE ALSO
137.Xr humanize_number 9
138.Sh HISTORY
139The
140.Fn humanize_number
141function first appeared in
142.Nx 2.0 .
141If
142.Dv HN_GETSCALE
143is specified, the prefix index number will be returned instead.
144.Sh SEE ALSO
145.Xr humanize_number 9
146.Sh HISTORY
147The
148.Fn humanize_number
149function first appeared in
150.Nx 2.0 .