[OpenWrt-Devel] Is printf considered to be guaranteed?
Yousong Zhou
yszhou4tech at gmail.com
Fri Oct 19 22:42:49 EDT 2018
On Sat, 13 Oct 2018 at 06:48, Sebastian Moeller <moeller0 at gmx.de> wrote:
>
> Dear mhei,
>
>
>
> > On Oct 12, 2018, at 20:53, Michael Heimpold <mhei at heimpold.de> wrote:
> >
> > Am Donnerstag, 11. Oktober 2018, 22:44:53 CEST schrieb Sebastian Moeller:
> >> Dear Luiz,
> >>
> >> thank you very much for this information. By now I have realized that printf
> >> evaluated locale (specifically LC_NUMERIC) at least on non-openwrt unices,
> >> which makes it unfortunately unusable for my purpose.
> >
> > forcing local, e.g.
> > LANG=C printf "%0.3f" 47.11
> > does not help?
>
> That might actually work, I tried LC_NUMERIC which did not work on openwrt.
>
> > Maybe you could elaborate on your purpose?
>
> Well I wanted to have a shell variable for configuring a buffer by the time in milliseconds required to empty that buffer (at a given bandwidth), but wanted to actually allow values down to microseconds.
> So I tried to use the following to effectively convert a value in (fractional) milliseconds into microseconds for use by the actual consumer like:
> TMP=1.015 ; printf %.0f\n "${TMP}e3"
Multiple a number by 1000 can be simulated with regex. Though I would
not use this when possible
f() {
local v="$1"
[ "${v%.*}" != "$v" ] || v="$v."
v=$(echo "${v}000" | sed -re 's/([0-9]+)\.([0-9]{3}).*/\1\2/')
echo "$1 $v"
}
f 1
f 1.
f 1.0
f 1.12
f 1.123
f 1.1234
Regards,
yousong
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list