HCL Interview Question
Developer Program EngineersCountry: India
Interview Type: In-Person
Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number. For example, the number 123.45 has a precision of 5 and a scale of 2.
That can be calculated by using the below formulas:
Operation Result precision
e1 + e2 max(s1, s2) + max(p1-s1, p2-s2) + 1
e1 - e2 max(s1, s2) + max(p1-s1, p2-s2)
e1 * e2 p1 + p2 + 1
Here operand expressions are denoted as expression e1, with precision p1 and scale s1. Same is for e2, p2 and s2.
e1 / e2 p1 - s1 + s2 + max(6, s1 + p2 + 1)
include <iostream>
#include <string>
using namespace std;
int main()
{
string value = to_string(static_cast<long double>(1234.56));
int precision = value.size();
int scale = value.size()-value.find('.')-1;
cout << precision << " " << scale;
std::cout << "The string is \"" << value << "\"\n";
return 0;
}
what do you mean by precision value? can you give and example and explain?
- JustCoding September 28, 2012