Title: | Human-Friendly Formatting Functions |
---|---|
Description: | Format quantities of time or bytes into human-friendly strings. |
Authors: | Dustin Sallings |
Maintainer: | Dustin Sallings <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.2 |
Built: | 2024-11-24 03:08:45 UTC |
Source: | https://github.com/dustin/humanformat |
These constants are used to express the number of nanoseconds in different time units.
kNanosecond kMicrosecond kMillisecond kSecond kMinute kHour
kNanosecond kMicrosecond kMillisecond kSecond kMinute kHour
These are useful for computing specific time durations or for converting from quantities in one unit to another unit (e.g. time in milliseconds to time in nanoseconds for duration formatting).
kNanosecond
: One nanosecond;
kMicrosecond
: One microsecond (1000 nanosecond);
kMillisecond
: One millisecond (1000 microseconds);
kSecond
: One second (1000 milliseconds);
kMinute
: One minute (60 seconds);
kHour
: One hour (60 minutes).
# To calculate 4 minute, 3 seconds and 14 microseconds: 4*kMinute + 3*kSecond + 14*kMicrosecond
# To calculate 4 minute, 3 seconds and 14 microseconds: 4*kMinute + 3*kSecond + 14*kMicrosecond
Formats a number of bytes into a human readable string.
When invoked as formatBytes
, SI sizes are used. You may
specify IEC sizes by using formatIECBytes
.
formatBytes(b, fmt="%.2f") formatSIBytes(b, fmt="%.2f") formatIECBytes(b, fmt="%.2f")
formatBytes(b, fmt="%.2f") formatSIBytes(b, fmt="%.2f") formatIECBytes(b, fmt="%.2f")
b |
Number of bytes |
fmt |
String format for the numeric part of the bytes |
# returns "934.82 MB" formatBytes(934818582) # returns "891.51 MiB" formatIECBytes(934818582) # returns c("8.43 KB", "3.52 KB", "624.62 KB", "46", "7.36 KB") formatBytes(c(8429, 3525, 624624, 46, 7357))
# returns "934.82 MB" formatBytes(934818582) # returns "891.51 MiB" formatIECBytes(934818582) # returns c("8.43 KB", "3.52 KB", "624.62 KB", "46", "7.36 KB") formatBytes(c(8429, 3525, 624624, 46, 7357))
Format individual or vectors of durations into human friendly text.
formatDuration(ns) formatNanoseconds(ns) formatMicroseconds(us) formatMilliseconds(ms) formatSeconds(s)
formatDuration(ns) formatNanoseconds(ns) formatMicroseconds(us) formatMilliseconds(ms) formatSeconds(s)
ns |
Duration in nanoseconds |
us |
Duration in microseconds |
ms |
Duration in milliseconds |
s |
Duration in seconds |
durationConstants
constants for various duration lengths
formatDuration(0) formatDuration(1) formatNanoseconds(34) formatMicroseconds(235) formatMilliseconds(2487) formatSeconds(7213) formatDuration(c(0, 1, 1000, 2039, 205958, 284859249525))
formatDuration(0) formatDuration(1) formatNanoseconds(34) formatMicroseconds(235) formatMilliseconds(2487) formatSeconds(7213) formatDuration(c(0, 1, 1000, 2039, 205958, 284859249525))
When working with durations, bytes, and other items with odd bases, it's often useful to format the numbers into human readable units.
formatDuration
: format durations
formatBytes
: format byte sizes
Package: | humanFormat |
Type: | Package |
Version: | 1.1 |
Date: | 2016-05-13 |
License: | MIT |
BugReports: | https://github.com/dustin/humanFormat/issues |
Dustin Sallings
Maintainer: Dustin Sallings <[email protected]>