COntvert and round off float

HOw would I round off a float? For example:

float numA = 26.07;
float numB = 40.00;
float answC;

answC = numA/numB * 100;

I want to have answC hold 65 not 65.175
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

      float answC= Math.floor(numA/numB * 100);
894359Author Commented:
That didn't work for me! Also I don't care if  answC holds the final value or not.
or you can declare ansWC as an int

int answC ;

answC = (int)(numA/numB * 100);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

BigDecimal answCdec=new BigDecimal(answC);
answC= answCdec.setScale(2).doubleValue();
oops should be ...

BigDecimal answCdec=new BigDecimal(answC);
answC= answCdec.setScale(0).doubleValue();
double numA = 26.07;
double numB = 40.00;
int answC;
answC = (int) Math.floor(numA/numB * 100);  // Note: return type is double. convert it to int (or float)
System.out.println("Answer C is ->" + answC);

If you want to declare the numbers as float, you should do:

float numA = (float) 26.07;  // value is double, convert it to float.
float numB = (float) 40.00; // value is double, convert it to float.
int answC;
answC = (int) Math.floor(numA/numB * 100);
System.out.println("Answer C is ->" + answC);
894359Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.