Decimal separator

Johnny Rosenberg gurus.knugum at gmail.com
Tue Dec 24 09:20:15 UTC 2013


2013/12/24 Colin Watson <cjwatson at ubuntu.com>

> On Mon, Dec 23, 2013 at 07:44:24PM +0100, Johnny Rosenberg wrote:
> > In a terminal (bash), is there something that I can type that gives me
> the
> > current decimal separator?
> >
> > For instance, if Swedish locale:
> >
> > $ echo "Current decimal separator: ${SomeVariable}"
> > Current decimal separator: ,
> > $
>
>   locale -k LC_NUMERIC
>
> (pipe through the obvious things if you want to use this in a script
> rather than just look at it)
>

Thanks. I tried:
$ locale -k LC_NUMERIC | grep decimal_point | sed 's/[^\.,]//g'
,
$

Works fine.

I don't need the thousands separator in this case, since I was only going
to use it for bc, which doesn't seem to use them.
I just want to use the decimal character on my numerical keypad when typing
the numbers to my script, and I just thought that it would be nice if the
simple script also works on a different setup.

So now I just let the user (me) type in the systems decimal separator, and
the script replace it with a decimal point, There some calculation, and the
answer has i decimal point that needs to be converted to the system's
decimal separator for output.

Thanks! Now I'm just going to make the script work as well…



Johnny Rosenberg


>
> On the other hand, if what you're really trying to do is to format a
> number with thousands separators, then you want some variant of:
>
>   env printf "%'d\\n" 1000
>
> (use a different conversion specifier such as 'g' rather than 'd' if you
> need a fractional part as well; the "env" forces the use of the printf
> binary from coreutils rather than any shell builtin, and in particular
> dash's builtin printf is inadequate for this, although bash's builtin
> printf is fine)
>
> --
> Colin Watson                                       [cjwatson at ubuntu.com]
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20131224/260cb45e/attachment.html>


More information about the ubuntu-users mailing list