On Jan 13, 4:54 pm, ZyX <[email protected]> wrote: > 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 > > > > signature.asc > < 1KViewDownload
Oh, yes, you're right. Please let me ask you one more thing: The command changes 300,12 in 300.1 (it changes the "," in "." after rounding). I would like to keep the "," I played a bit with submatch but that didn't the trick. -- 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
