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


-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to