Converting Months into years.
-
I am trying to display then data that is captured in months to be shown as years. For example if someone have been with us for 18 months, I want to display it as 1.5 years. I have attempted to do so by writing the code below but to no avail. Any assistance will be greatly appreciated. public static int YearsFromMonths(int months) { int evenMonths = (months /12); int remainingMonths =(months % 12); decimal fractionOfYear = Convert.ToDecimal(((remainingMonths) * .0833)/10); if((months % 12) == 0) { return evenMonths; } else { return fractionOfYear; } Thanks.
Skan If you knew it would not compile why didn't you tell me?!?!?!
-
I am trying to display then data that is captured in months to be shown as years. For example if someone have been with us for 18 months, I want to display it as 1.5 years. I have attempted to do so by writing the code below but to no avail. Any assistance will be greatly appreciated. public static int YearsFromMonths(int months) { int evenMonths = (months /12); int remainingMonths =(months % 12); decimal fractionOfYear = Convert.ToDecimal(((remainingMonths) * .0833)/10); if((months % 12) == 0) { return evenMonths; } else { return fractionOfYear; } Thanks.
Skan If you knew it would not compile why didn't you tell me?!?!?!
If you want to return a fraction, return a float. float years = months/12.0F;
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
If you want to return a fraction, return a float. float years = months/12.0F;
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
This may sound ignorant but what's the difference between Decimal and float? The couple of Apps I wrote in C++ I never heard of decimal. I guess this new with .Net. Also why the "F" after the number for float? .Net suck...........but I guess I have to adapt.
Skan If you knew it would not compile why didn't you tell me?!?!?!
-
I am trying to display then data that is captured in months to be shown as years. For example if someone have been with us for 18 months, I want to display it as 1.5 years. I have attempted to do so by writing the code below but to no avail. Any assistance will be greatly appreciated. public static int YearsFromMonths(int months) { int evenMonths = (months /12); int remainingMonths =(months % 12); decimal fractionOfYear = Convert.ToDecimal(((remainingMonths) * .0833)/10); if((months % 12) == 0) { return evenMonths; } else { return fractionOfYear; } Thanks.
Skan If you knew it would not compile why didn't you tell me?!?!?!
Hi, If its 18 months you will show as 1.5 years. What if its 16 months or 15 months. How will that be displayed. This is for my information, so that I can work on it
Thanking you in Advance Kind Regards Pratik Shah
-
Hi, If its 18 months you will show as 1.5 years. What if its 16 months or 15 months. How will that be displayed. This is for my information, so that I can work on it
Thanking you in Advance Kind Regards Pratik Shah
If its 15 months then it should display 1.25 and if its 16 months then should display 1.3 (not the on decimal place because in reality it 1.3333). I think if we take the radical vairable and multiply it by .83333 then round it off to on or two decimal place that should work.
Skan If you knew it would not compile why didn't you tell me?!?!?!
-
If you want to return a fraction, return a float. float years = months/12.0F;
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
I am trying to display then data that is captured in months to be shown as years. For example if someone have been with us for 18 months, I want to display it as 1.5 years. I have attempted to do so by writing the code below but to no avail. Any assistance will be greatly appreciated. public static int YearsFromMonths(int months) { int evenMonths = (months /12); int remainingMonths =(months % 12); decimal fractionOfYear = Convert.ToDecimal(((remainingMonths) * .0833)/10); if((months % 12) == 0) { return evenMonths; } else { return fractionOfYear; } Thanks.
Skan If you knew it would not compile why didn't you tell me?!?!?!