Hi
Is there a function similar to "SetDlgItemInt()" which is able to work with non integers (decimals)?
Apparently SetDlgItemInt() is not required for float or double types, what do you recommend?
Thank you
Printable View
Hi
Is there a function similar to "SetDlgItemInt()" which is able to work with non integers (decimals)?
Apparently SetDlgItemInt() is not required for float or double types, what do you recommend?
Thank you
Convert data to string, use SetDlgItemText. To convert data to a string, you can use sprintf.
You could use SetDlgItemText() - then just create the text that you want to see.
gg
Ok That was actually my solution before... I can stick to that
But In that case I have problems with determination of number of decimals...
The program does not determine the decimals on its own so I have to do sprintf(char*, "%.*f", iDecimalPlaces, iInteger);
Do you have a solution for this?
sprintf() is what I would use :)
gg
Sorry still donīt get it... Just tried a few possibilities but all failed...
This is one of them sprintf(chTotal, "%f", iTotal);
Seems like sprintf always return 6 decimals even if they are equal to NULL.
Well, you can limit it to a fix number of decimals through
sprintf(chTotal, "%0.2f", iTotal)
This will only use two decimals.
Yes that is actually my problem...
I need a function that determines for me number of decimals of the double type.
Then I use the returned value as you did
But the thing is that it will convert all decimals into a string, unless you specify otherwise.
All right
What else do you recommend me. I agree this is not the best solution in this case
The number of decimal points to show is completely up to you. What does the value represent? A measurement? Money?
Are you looking for locale dependant information - like the number of decimal points to show for a money value?
gg
I am creating a little calculator... So I need my answers to be in correct count of decimals...
If I process 1/8 it should return 0.125 not 0.125000 or 0
Sorry I did not state that its for calculator use before
Just pass %f, and it will print any available decimals.
Beware that floating points in somewhat inaccurate, so 1/8 can also return 0.12500001 or something. Don't know if it can happen to this particular equation, but it can happen to certain ones.
1/8 is integer - that's why it is 0
use 1.0/8 or 1/8.0
What Every Computer Scientist Should Know About Floating-Point Arithmetic
End the end, if you want exact precision - use a 3rd party library like GMP.
gg