On 10/06/08 21:02, Bram Moolenaar wrote: > > Ben Schmidt wrote: [...] >>>> 4. Cosmetic thing but truncating of 0s in floating numbers would be user >>>> friendly (eg. store and display 0.5 instead of 0.500000) >>> I don't see an argument to printf() to get this. >> Yeah, that'd be a good improvement. > > I mean: Vim is using the library printf() to do the conversion, but I > don't see a way to tell printf() to omit superfluous zeroes. [...]
It can be done easily (well, sort of) in vim-script post-processing: function FloatToStr(f) let retval = printf('%g', a:f) if retval == '0.000000e+00' " special case let retval = '0.0' elseif retval == '-0.000000e+00' " another special case let retval = '-0.0' elseif retval =~ 'e\|[^0]$' " exponent or no trailing zeroes " do nothing else " remove trailing zeroes let retval = retval[:match(retval, '0*$') - 1] " but leave at least one digit after the decimal point if retval =~ '\.$' let retval .= '0' endif endif return retval endfunction Best regards, Tony. --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---