I tried to use the arithmetic register with a fraction (7/8) and it returned 0! How do I exert better control over the register so that it gives me what I want?
The literal sequence I used, while in insert mode:
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
As none of your numbers contains a decimal point (
:help floating-point-format), Vim treats the expression as integer division, and also gives an integer result.
Simply specify one or both numbers as floats, and you'll get the expected result:
For more control (number of digits, precision, padding), use
printf() with the corresponding format specifications.