Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • though usually one would round when reducing the number of digits, so 0.000919104 should turn into .00092 Commented Feb 26 at 7:49
  • This should be the case with the method I introduced in my last edit, I've added the first one as native-only example and sometimes rounding may explicitly be not desired, which seems to be harder to achieve efficiently. printf will sometimes not propagate rounding to left digits, though, like in printf "TO_ROUNDUP: %.3f\n", "0.022492", but that's the default, not a problem of my method. I couldn't even change this by using it inside awk and setting different a ROUNDMODE, which surprised me. Inconveniently, I couldn't manage to get around extended pattern matching in 1st example. Commented Mar 3 at 15:46
  • hmmh, what do you mean with propagating rounding? 0.022492 rounded to three digits after the decimal point is 0.022, it unambiguously rounds down. Does some tool do it differently? Commented Mar 3 at 16:42
  • Here, it round down, when using printf "TO_ROUNDUP: %.3f\n", "0.022942", it'll round up to 0.023. I figured, when specifying 3 decimal digits, it should be 0.22 in both cases, since it's the 4th digit, that is, or is not propagated left for rounding. Commented Mar 11 at 14:24