How to display numbers with decimals

1
2
3
float put;
put = 6/120;
cout << put;


This outputs 0. Why is it so and how can I make it output 6/120 in a more precise way?
Last edited on
Numerator or denominator or both should be float. Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

int main(){

    float result = 0;

    result = 6 / 120;
    std::cout << "Result with integers: " << result << std::endl;

    result = 6.f / 120;
    std::cout << "Result with float and integer: " << result << std::endl;

    result = 6.f / 120.f;
    std::cout << "Result with floats: " << result << std::endl;

    result = 6.0 / 120.0;
    std::cout << "Another result with floats: " << result << std::endl;
}
Topic archived. No new replies allowed.