//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 void RoundHigherTest() { var yieldTest = new BakeryInventoryProject.Models.YieldCalculations(); var actual = yieldTest.RoundToInteger(2.33m); var expected = 2; Assert.AreEqual(expected, actual); }
//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); }
public decimal UpdateMeasurementBasedOnMultiplier(decimal measurementValue, decimal multiplier) { var yield = new YieldCalculations(); return(yield.RoundToNthPlace((measurementValue * multiplier), 2)); }
public decimal DivideDecimalInHalfAndRoundToHundred(decimal value) { var yield = new YieldCalculations(); return(yield.RoundToNthPlace((value / 2), 2)); }