I\'m new to C++. I have a double variable double a=0.1239857 and I want to limit variable a from decimal point two digits. So a will b
double a=0.1239857
a
An actual rounding solution would be x = floor(100*x + 0.5) / 100; assuming the value to be rounded is in a variable "x".
x = floor(100*x + 0.5) / 100;
The x = floor(100*x) / 100; recommended by others here will actually truncate the number to 2dp instead.
x = floor(100*x) / 100;