All the working above assumes that the radix character (also known as the decimal separator) is ., as in most English locales.  Other locales use , instead, and some shells have a built-in printf that respects locale.  In thisthese shells, you may need to set LC_NUMERIC=C to force the use of . as radix character, or write /usr/bin/printf to prevent use of the built-in version.  This latter is complicated by the fact that (at least some versions) seem to always parse arguments using ., but print using the current locale settings.
                
                    Toby Speight 
                
                
- 9.4k
- 3
- 32
- 54
                
                    Toby Speight 
                
                
- 9.4k
- 3
- 32
- 54
                        The function *is* POSIX shell, not just Bash - but some shells have a bulit-in printf that handles locale differently from standard printf
                    
                
                
                    Toby Speight 
                
                
- 9.4k
- 3
- 32
- 54
                        missing quotes, %f/%g not POSIX, so using bash where we know the printf builtin supports it, not about radix character.
                    
                
                
                    Stéphane Chazelas 
                
                
- 584.8k
- 96
- 1.1k
- 1.7k
                        Fixed a bashism and a bug with exponents of 8 or 9 (leading zero implies octal in arithmetic expansion)
                    
                
                
                    Toby Speight 
                
                
- 9.4k
- 3
- 32
- 54
 
                 
                 
                