adjust-dpi.sh rounding problem

Geert Janssens geert.gnucash at kobaltwit.be
Thu Aug 25 04:00:01 EDT 2016


On Thursday 25 August 2016 09:34:34 Chris Good wrote:
> Thanks for your reply.
> It's annoying that identify doesn't use the locale decimal separator.
> BTW, my locale is en_AU.UTF-8.
> 
> Are you sure bash printf doesn't round? It does for me in Ubuntu,
> although I was surprised to see 0.005 sometimes does not round up
> (I guess it's just the typical floating point rounding problem).
> printf "%.2f\n", 1.235
> 1.24
> printf "%.2f\n", 4321.235
> 4321.23				###???###
> printf "%.2f\n", 4321.2351
> 4321.24
> LC_ALL=nl_BE.UTF-8 printf "%.2f\n", 4321,235
> 4321,23
> LC_ALL=nl_BE.UTF-8 printf "%.2f\n", 4321,2351
> 4321,24
> 
> The 0.005 sometimes not rounding up will not be an issue for
> adjust-dpi.sh as the numbers are a lot closed to the rounded value
> than 0.005.

I can't reproduce the truncating behavior today. It rounds as you 
describe so I'll just forget about that. I probably got confused at some 
point.

> 
> Anyway, I decided to use awk to strip the trailing
> "(space) PixelsPerCentimeter"
> and do the rounding in one step.
> 
> When you get a chance (or some-else on Fedora 23?), could you please
> test: echo 4321.159 | awk '{ printf("%.2f\n", $1) }'
> 4321.16
> 
Works as expected. Good choice!

> I'm also surprised to see my awk is also NOT using the locale decimal
> separator:
> $ LC_ALL=nl_BE.UTF-8 echo 4321,159 | awk '{ printf("%.2f\n", $1) }'
> 4321.00
> LC_ALL=nl_BE.UTF-8 echo 4321.159 | awk '{ printf("%.2f\n", $1) }'
> 4321.16
> 
> I've never before had to worry much about different locales - Oh well,
> I'll get there :-)

This seems to work fine in all locales. Thanks!

Geert


More information about the gnucash-devel mailing list