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
Float to Integer with 2 Decimal points
Moderator: Benj
-
- 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
Hi Abhi.
This is nice and easy to do.
it's IntVariable = FloatVariable * 100
This is nice and easy to do.
it's IntVariable = FloatVariable * 100
Martin
-
- Valued Contributor
- Posts: 1189
- 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
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
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
- AbhijitR
- Posts: 299
- Joined: Fri Nov 07, 2014 12:48 pm
- Location: Pune, India
- Has thanked: 280 times
- Been thanked: 79 times
- Contact:
Re: Float to Integer with 2 Decimal points
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
Thank you again to both of you, have a wonderful evening and and a nice weekend, cheers...
Abhi
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
Thank you again to both of you, have a wonderful evening and and a nice weekend, cheers...
Abhi