Hello...first, sorry for my bad english, i hope you are understand what i mean.
i`m doing some project with lots of float data type. now i need to convert the result of calculation(which is a float data type) to longword so i can use the DIV or MOD in mikrobasic PRO 3.80. anyone can help me?
no body can help you because nobody knows how you intend to convert a float to long (?). people may be able to help you with the conversion itself but you have to decide how you want to convert it.
If you have a float f and a long variable l, you can simply write l = f, and the implicite standard C conversion will assign the integer part of f to l. That's the simple answer to your question in terms of the C language standard.
If you intend something different, like a fixed point representation of a float value, you have to define the respective numeric format first. You basically have to specify the number of integer and fractional bits.
Thank you for the answer guys..to make things clearer..suppose i have a float f=98765.6988. Now i just want to convert it to longword with rounding to nearest integer (so the result of example above will be 98766)..thank you for your attention
just think about it: FvM has provided an answer to you that is accurate if your float type f has no decimal points. aka FvM's approach would be correct if f is between 98765.0 - 98765.4.
that approach would be wrong if f is [98764.5 - 98764.9].
essentially, you want a conversion that pushes a number between 98764.5 - 98765.4 (that number, per your desire, will convert to 98765) to above 98765.0 but less than 98765.9 for FvM's approach to be correct.
there are simply too many ways to do that, with one particular way being extremely efficient.
The exact behaviour of the implicite C type conversion or (long) type cast isn't specified by the C standard as far as I know. Particularly the IEC spec opens this point for implementation dependance. If a certain implementation is simply cutting the fractional part, it may be different with another.
If you want a clear behaviour, use round(), floor() or ceil() - whatever you want.