Ive had an assignment for a huge program and I conquered it all well but once again, I get caught on one of the simplest parts because we weren't really taught how to actually do this. So say you have a distance of 325 inches. I then would convert that to feet by dividing it by 12 and getting 27.083. I have no clue how to return that value as a String and tell the program that what's before the decimal is the feet (the 27) and whats after the decimal (the .08 which I have to also tell the program to round) are the inches. I also have to do this with time as well to do this with time so lets say the longest time is 60.3 seconds. I have no idea how to convert that to each seperate part as well as in 1 minute and .03 seconds.

Thanks alot I really do appreciate it

(I thought of using a String tokenizer or a split method but again, we were never taught that in my class so why would we use it? I know it has to be more simple)

Originally posted by jiju ka:

If needed String.length() can be used to find length and trim can be used to trim off white spaces.

There are other ways to accomplish the same.

Hey

I wasnt sure of how to exactly use the indexof method and the substring. Did I get anything right because I still am getting errors.

first we have a 325 inches, we divide by 12 and get 27.0833333 we assign it to a value but only the 27 part. Then i will multiply the 27 * 12 and get 324, then we substract 325 - 324 and get 1, this is the inches part

double a = 325;

int f = (int) a / 12;

int in = (int) a - (f * 12);

She will remember your heart when men are fairy tales in books written by rabbits.<br /> As long as there is duct tape... there is also hope.

first we have a 325 inches, we divide by 12 and get 27.0833333 we assign it to a value but only the 27 part. Then i will multiply the 27 * 12 and get 324, then we substract 325 - 324 and get 1, this is the inches part

double a = 325;

int f = (int) a / 12;

int in = (int) a - (f * 12);

Your method will work, but it is quicker to declare the

*a*variable as an int, then find the feet using

*a / 12*and the inches using

*a % 12*.

Beware of repeated dividing and multiplying, otherwise one day you will get

*0.0833333 * 12 = 0.9999996*, which when cast to an int comes out as 0.

This could grow with more constructors for feet & inches, conversions to yards, miles, furlongs, whatever you need.

For grins, google "123 inches in feet". They don't break down the anwwer you want, tho.

[ November 01, 2005: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi