Float to Integer with 2 Decimal points

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Float to Integer with 2 Decimal points

Post 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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Float to Integer with 2 Decimal points

Post by medelec35 »

Hi Abhi.
This is nice and easy to do.
it's IntVariable = FloatVariable * 100
Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Float to Integer with 2 Decimal points

Post 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

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: Float to Integer with 2 Decimal points

Post 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

Post Reply