Hey, I am making simple calculator using gtkmm library. But my question does not relate with gtkmm stuff. I will make it short. To display the value in my calculator, I use string. You push button 6, I put 6 into (double) buf1. You push button +, I set the flag to PLUS. You push button 9, I put 9 into (double) buf2. You push button =, I calculate buf1 + buf2 then I display the result in my calculator display. But before I do that, I must convert double to string because the display in my calculator only display string. Only string.
After googling, I found this function:
The problem is........ it will display 54.000000 in my example case, not 54. Is there anyway I can convert double to string better than function above.Code:std::string dtos(double dbl){ char buf[BUFSIZ]; sprintf(buf, "%lf", dbl); return buf; }
My calculator display has 36 character place. So is there any function that can set my (double)result presicion to >30 before I can convert it to string so my string will have a high presicion, in my case is >30. I know how to set presicion so that I can display the double with high presicion like this:
But my calculator can only display string. What I am afraid of is if I convert double to string, it will loose high precision.Code:cout << setiosflags(ios::fixed) << setprecision(34) << c << endl;
So, please help me to find the function to convert double to string that will not loose high presicion but not display unnessecary 0.
If the result is 54, it will display 54.
If the result is 234.452342134124123412, it will display 234.452342134124123412.
If the result is 1234.234, it will display 1234.234 not 1234.23400000000
Thanx guyz.