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

- 02-11-2008GordonVariable Type issue
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 - 02-11-2008Elysia
Convert data to string, use SetDlgItemText. To convert data to a string, you can use sprintf.

- 02-11-2008Codeplug
You could use SetDlgItemText() - then just create the text that you want to see.

gg - 02-11-2008Gordon
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? - 02-11-2008Codeplug
sprintf() is what I would use :)

gg - 02-11-2008Gordon
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. - 02-11-2008Elysia
Well, you can limit it to a fix number of decimals through

sprintf(chTotal, "%0.2f", iTotal)

This will only use two decimals. - 02-11-2008Gordon
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 - 02-11-2008Elysia
But the thing is that it will convert all decimals into a string, unless you specify otherwise.

- 02-11-2008Gordon
All right

What else do you recommend me. I agree this is not the best solution in this case - 02-11-2008Codeplug
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 - 02-12-2008Gordon
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 - 02-12-2008Elysia
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. - 02-12-2008vart
1/8 is integer - that's why it is 0

use 1.0/8 or 1/8.0 - 02-12-2008Codeplug
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