//automatically rounds to the hundreth decimal place public decimal CalculateFractionToDecimal(string fraction) { var round = new YieldCalculations(); var split = new SplitFraction(); var fractionSplit = new string[] { }; var properFraction = new string[] { }; var wholeNumber = 0m; var numerator = 0m; var denominator = 0m; if (!fraction.Contains('/')) { return(System.Convert.ToDecimal(fraction)); } if (!fraction.Contains(' ')) { fractionSplit = SplitFraction(fraction); numerator = System.Convert.ToDecimal(fractionSplit[0]); denominator = System.Convert.ToDecimal(fractionSplit[1]); } else if (fraction.Contains(' ')) { properFraction = split.SplitProperFractionIntoWholeNumberAndFraction(fraction); fractionSplit = SplitFraction(properFraction[1]); wholeNumber = System.Convert.ToDecimal(properFraction[0]); numerator = System.Convert.ToDecimal(fractionSplit[0]); denominator = System.Convert.ToDecimal(fractionSplit[1]); var decimalValue = (numerator / denominator) + wholeNumber; return(round.RoundToNthPlace(decimalValue, 2)); } return(round.RoundToNthPlace((numerator / denominator), 2)); }
public string[] GetImproperFractionParts(string measurement) { var split = new SplitFraction(); var properFraction = split.SplitProperFractionIntoWholeNumberAndFraction(measurement); var smallFraction = new string[] { }; var wholeNumber = ""; var numerator = ""; var denominator = ""; var improperNumerator = ""; if (properFraction.Count() == 1) { smallFraction = split.SplitFractionIntoNumeratorAndDenominator(properFraction[0]); numerator = smallFraction[0]; denominator = smallFraction[1]; var improperFractionArray = new string[] { numerator, denominator }; return(improperFractionArray); } else { smallFraction = split.SplitFractionIntoNumeratorAndDenominator(properFraction[1]); wholeNumber = properFraction[0]; numerator = smallFraction[0]; denominator = smallFraction[1]; improperNumerator = ((System.Convert.ToInt32(wholeNumber) * System.Convert.ToInt32(denominator)) + System.Convert.ToInt32(numerator)).ToString(); var improperFractionArray = new string[] { improperNumerator, denominator }; return(improperFractionArray); } }
//calculate hte improper fraction //create a to do list here. //steps: /* - split measurement value from type * - split measurement, if proper fraction then create as improper fraction * - calculate adjusted measurement from improper fraction * - adjust improper fraction back to proper fraction * - concatenate measurement back * */ public decimal MultiplyOriginalMeasurementToDecimal(string measurement, decimal multiplier) { var yield = new YieldCalculations(); var split = new SplitFraction(); var parseFractoDec = new ParseFractionToDecimal(); var parseDectoFrac = new ParseDecimalToFraction(); var splitMeasurement = split.SplitMeasurementValueAndName(measurement); string measurementValue = splitMeasurement[0]; var decimalValueOfFraction = parseFractoDec.CalculateFractionToDecimal(measurementValue); var updatedDecimalValue = (decimalValueOfFraction * multiplier); var updatedMeasurementBasedOnMultiplier = yield.RoundToNthPlace(updatedDecimalValue, 2); return(updatedMeasurementBasedOnMultiplier); }