c# - Calculate days in years and months? -
how calculate days in years , months in c#? per example :
if 1. days = 385
need display year= 1.1
(i.e. 1 year 1 month) 2. days= 234
need display year =0.7
(i.e 0 year 7 months)
how can calculate in c#?
i did days=234 /365
, result coming 0.64 (i.e. 0 year 6 months). 7 months.
how accurate year , months.
assuming month of one-twelfth of year, , want ignore partial months (based on saying expect 7 example 7.688 months, then:
int days = 234; double years = (double)days / 365.242199; int wholeyears = (int)math.floor(years); double partyears = years - wholeyears; double approxmonths = partyears * 12; string horribleformat = string.concat(wholeyears, ".", approxmonths);
Comments
Post a Comment