Reply to message «Re: rounding numbers», 
sent 18:49:00 13 January 2011, Thursday
by rameo:

> All ok, except when "." and "," is used together.
> 
> p.e. 15.000,56
> gives 15.1
> and not 15.001
> 
> Also Christians command gives 15.1
Of course it does. You should adjust regex that captures numbers to include 
numbers with dot and add new substitute call that will remove them.

Original message:
> On Jan 13, 4:20 pm, ZyX <[email protected]> wrote:
> > Reply to message «Re: rounding numbers»,
> > sent 14:21:20 13 January 2011, Thursday
> > 
> > by rameo:
> > > > So put it all together like this:
> > > > :%s/\d\+,\d\+/\=float2nr(round(str2float(substitute(submatch(1), ',',
> > > > :'.',
> > > > 
> > > > ''))))/g
> > > > 
> > > > (this is one line, in case the mail get's mangled)
> > 
> > This expression can be easily simlified using printf builtin:
> > :%s/\d\+,\d\+/\=printf("%.0f",
> > :str2float(substitute(submatch(0),',','.','')))/g
> > 
> > The fact that float will be rounded (not truncated) is mentioned in
> > documentation (`man 3 printf', in vim doc this is omitted), so I assume
> > it to be stable behavior. You may test it yourself though: ``echo
> > printf('%.0f', 1.5)'' prints 2, ``echo printf('%.0f', 1.4)'' prints 1.
> > Note that with printf you may round to arbitrary precision, not only to
> > integer as with `round()'.
> 
> Your solution is very nice also.
> Great to be enable to change the precision parameter.
> I did experiences.
> All ok, except when "." and "," is used together.
> 
> p.e. 15.000,56
> gives 15.1
> and not 15.001
> 
> Also Christians command gives 15.1

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to