Page 1 of 1

Float to Integer with 2 Decimal points

Posted: Sat Jul 24, 2021 2:29 pm
by AbhijitR
Hello!

Kindly excuse to repeat the topic but i probably did not find any good pointer.

My question is how can i convert the Float value (25.50) to Integer (this is what i expect 2550) so the decimal point is removed and the digits after the decimal point is clubbed with the number before decimal which is 25, what should i do, use the "TypeConversions1" or C block, kindly suggest how to use.

Thank you.

Abhi

Re: Float to Integer with 2 Decimal points

Posted: Sat Jul 24, 2021 3:30 pm
by medelec35
Hi Abhi.
This is nice and easy to do.
it's IntVariable = FloatVariable * 100

Re: Float to Integer with 2 Decimal points

Posted: Sat Jul 24, 2021 3:33 pm
by mnf
Hi Abhi,

It's not easy to do a straight conversion from the binary representation of a float to an integer..
You'll just need to do *100 however for pretty good result (some values can't be exactly represented in the float type)

So int = float * 100 will give an int with two decimal places..

You could also convert to a string - remove the decimal point then convert the string to an int - but its more work

... Martin beat me to it!

Martin

Re: Float to Integer with 2 Decimal points

Posted: Sat Jul 24, 2021 3:58 pm
by AbhijitR
Hello! to both Martin
good evening

This is why you all are Valued Contributors, i really appreciate your time and suggestions always, you made it so simple and i was going all the way round thinking now what to do. :?: and now solved :D

Thank you again to both of you, have a wonderful evening and and a nice weekend, cheers...

Abhi