|
-
October 24th, 2024, 12:33 PM
#5
Re: Round off or trucate double to two decimal places
> The value can only take the distict values as per requirement . ie { 6.22, 3.44, 7.8, 0, 1, 2}
So perhaps don't treat them as floats, but as fixed point numbers instead.
Internally, you would store these as
622, 344, 780, 0, 100, 200
You would read 6.22 as a pair of integers, separated by a dot.
Code:
class frac {
int int_part;
int frac_part;
public:
friend ostream & operator << (ostream &out, const frac &c);
friend istream & operator >> (istream &in, frac &c);
};
https://www.geeksforgeeks.org/overlo...n-operators-c/
The somewhat interesting part will be handling the optional dot.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|