Double getlength
-
Hi All Can i get double length?I have a variable double l=111.98987744,so can i get
l length
Plz help me.
You mean the size in bytes of a double ? If yes, use the sizeof operator:
int lenght = sizeof(double);
Cédric Moonen Software developer
Charting control [v2.0] OpenGL game tutorial in C++ -
You mean the size in bytes of a double ? If yes, use the sizeof operator:
int lenght = sizeof(double);
Cédric Moonen Software developer
Charting control [v2.0] OpenGL game tutorial in C++ -
Thanks for reply. i use your code.It's return always 8.
double tr=111.989877445678;
int lenght = sizeof(tr);
result is length=8;Yes, that's the size of a double. Errr.. wait, you make me wonder. Are you asking for the lenght of the string representing the double ? If yes, there's no way to know that with precision because of the floating point precision. For instance, if you store 1 in a double, its value won't be exactly 1, but maybe 1.00000000001. So, it's not what you expect. Anyway, why do you want know something like that ? It doesn't make a lot of sense... If you want to convert your double to a string, you can always specify the precision you want to keep.
Cédric Moonen Software developer
Charting control [v2.0] OpenGL game tutorial in C++ -
Yes, that's the size of a double. Errr.. wait, you make me wonder. Are you asking for the lenght of the string representing the double ? If yes, there's no way to know that with precision because of the floating point precision. For instance, if you store 1 in a double, its value won't be exactly 1, but maybe 1.00000000001. So, it's not what you expect. Anyway, why do you want know something like that ? It doesn't make a lot of sense... If you want to convert your double to a string, you can always specify the precision you want to keep.
Cédric Moonen Software developer
Charting control [v2.0] OpenGL game tutorial in C++you can always specify the precision you want to keep
yes i am converting double to Cstring(CSting str.formate("%.4f",double)). But i want to convert same values like if double tr=98.29982355 then i want to convert Cstring str=98.29982355 and when tr=9.89 then str=9.89. So i think if i have a length of double then it's make to easy. Any way there is any more option to convert double to CString. Plz help me
-
you can always specify the precision you want to keep
yes i am converting double to Cstring(CSting str.formate("%.4f",double)). But i want to convert same values like if double tr=98.29982355 then i want to convert Cstring str=98.29982355 and when tr=9.89 then str=9.89. So i think if i have a length of double then it's make to easy. Any way there is any more option to convert double to CString. Plz help me
Davitor wrote:
But i want to convert same values like if double tr=98.29982355 then i want to convert Cstring str=98.29982355 and when tr=9.89 then str=9.89. So i think if i have a length of double then it's make to easy.
Well, but that's what I was explaining: tr=98.29982355, in that specific case, it is very probable that your double will be stored with some imprecision (for instance tr=98.299823499999999). There's no way for the computer to guess which precision you want to keep, that's up to you to tell to the computer where the number should be rounded when converting to string. I suggest you read this article[^] about floating point precision.
Cédric Moonen Software developer
Charting control [v2.0] OpenGL game tutorial in C++ -
you can always specify the precision you want to keep
yes i am converting double to Cstring(CSting str.formate("%.4f",double)). But i want to convert same values like if double tr=98.29982355 then i want to convert Cstring str=98.29982355 and when tr=9.89 then str=9.89. So i think if i have a length of double then it's make to easy. Any way there is any more option to convert double to CString. Plz help me
Why don't you use
str.Format("%f", d)
then? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]