Vasily Guzov
Vasily Guzov

Reputation: 33

How to divide a smaller number by a bigger number in VIM?

In vim editor, when I try to divide numbers using the command

<C-r>= 320 / 1024

I get 0. How to fix it?

Upvotes: 3

Views: 522

Answers (2)

Andrei
Andrei

Reputation: 5637

You have to have one of the numbers as a float one:

320 / 1024.0 will give what you want. More info here

Upvotes: 7

Sudheesh Singanamalla
Sudheesh Singanamalla

Reputation: 2297

What you're trying to do is integer division. While doing integer division some sample results are as follows:

1/3 = 0
5/3 = 1

but converting either the numerator/denominator to a floating point value will return a floating point result.

1.0/3 = 0.333333
5/3.0 = 1.666667

Therefore what you're looking for is 320/1024.0 or 320.0/1024 or 320.0/1024.0 The result of which is 0.3125

Upvotes: 1

Related Questions