var schemeduration = '1.5';// 1 year , 5 months var schemeduration= (parsefloat(schemeduration) * 12).tofixed(0) ; alert(schemeduration); 1.1 = 13 months 1.2 = 14 months 1.3 = 15 months 1.4 = 16 months 1.5 = 17 months 1.6 = 18 months 1.7 = 19 months 1.8 = 20 months 1.9 = 21 months 1.10 = 22 months 1.11 = 23 months 1.12 = 24 months
how display exact months given years in decimal.for above given should display 17 getting value 18. there 12 months in year need output calculated in terms of months
this should work:
var schemeduration = '1.5'; if(schemeduration.indexof('.') === -1) schemeduration += '.0'; var years = math.floor(parsefloat(schemeduration)); var months = parseint(schemeduration.split('.')[1], 10); schemeduration = years * 12 + months; alert(schemeduration);
Comments
Post a Comment