public static decimal SmartRound(decimal paramBigDecimal, int paramInt) { bool @bool = (cmp(paramBigDecimal, ZERO) < 0) ? 1 : 0; decimal bigDecimal = paramBigDecimal.abs(); sbyte b1 = 0; sbyte b2 = 0; while (b2 < 32 - paramInt) { BigDecimalFixed bigDecimalFixed = new BigDecimalFixed(bigDecimal.toBigInteger()); decimal bigDecimal1 = bigDecimal - bigDecimalFixed; bool bool1 = (approx(bigDecimal1, ONE, paramInt) == 0) ? 1 : 0; if (approx(bigDecimal1, ZERO, paramInt) == 0 || bool1) { if (bool1) { null = bigDecimalFixed.add(ONE); } null = null.setScale(37, ROUND_DOWN).movePointLeft(b1); if (@bool) { null = null.negate(); } return(null.setScale(b1, ROUND_DOWN)); } b2++; bigDecimal = bigDecimal.movePointRight(1); b1++; } return(paramBigDecimal); }
public static bool isInt(decimal paramBigDecimal, int paramInt) { BigDecimalFixed bigDecimalFixed = new BigDecimalFixed(paramBigDecimal.toBigInteger()); decimal bigDecimal = paramBigDecimal - bigDecimalFixed.abs(); return(approx(bigDecimal, ZERO, paramInt) == 0 || approx(bigDecimal, ONE, paramInt) == 0); }
private decimal notNullBigDecimal(HSSFCell paramHSSFCell, double paramDouble) { decimal bigDecimal = new BigDecimalFixed("" + paramDouble); if (paramHSSFCell == null) { return(bigDecimal); } if (paramHSSFCell.CellType == 0) { bigDecimal = new BigDecimalFixed("" + paramHSSFCell.NumericCellValue); } else if (paramHSSFCell.CellType == 2) { CellValue cellValue = this.o_evaluator.evaluate(paramHSSFCell); if (cellValue.CellType == 0) { bigDecimal = new BigDecimalFixed("" + cellValue.NumberValue); } } else { try { bigDecimal = new decimal(paramHSSFCell.RichStringCellValue.String); } catch (Exception) { return(bigDecimal); } } return(bigDecimal); }
private static decimal ComputePi() { BigDecimalFixed bigDecimalFixed1 = new BigDecimalFixed("0.2"); decimal bigDecimal1 = mult(atan(bigDecimalFixed1), FOUR); BigDecimalFixed bigDecimalFixed2 = new BigDecimalFixed("239"); decimal bigDecimal2 = atan(recip(bigDecimalFixed2)); bigDecimal1 = bigDecimal1 - bigDecimal2; bigDecimal1 = mult(bigDecimal1, FOUR); return(bigDecimal1.setScale(37, ROUND_DOWN)); }
private decimal notNullBigDecimal(HSSFCell paramHSSFCell, double paramDouble) { BigDecimalFixed bigDecimalFixed = new BigDecimalFixed("" + paramDouble); if (paramHSSFCell == null) { return(bigDecimalFixed); } if (paramHSSFCell.CellType == 0) { bigDecimalFixed = new BigDecimalFixed("" + paramHSSFCell.NumericCellValue); } return(bigDecimalFixed); }
private static decimal realRoot(int paramInt, decimal paramBigDecimal) { decimal bigDecimal4; if (paramInt < 2) { return(null); } if (cmp(paramBigDecimal, ZERO) == 0) { return(ZERO); } if (cmp(paramBigDecimal, ONE) == 0) { return(ONE); } paramBigDecimal = paramBigDecimal.abs().setScale(37, ROUND_DOWN); BigDecimalFixed bigDecimalFixed = new BigDecimalFixed("" + paramInt); decimal bigDecimal1 = bigDecimalFixed.subtract(ONE); bigDecimal1 = bigDecimal1.setScale(37, ROUND_DOWN).divide(bigDecimalFixed, ROUND_DOWN); decimal bigDecimal2 = paramBigDecimal.divide(bigDecimalFixed, ROUND_DOWN); decimal bigDecimal3 = ONE; if (cmp(paramBigDecimal, ONE) > 0) { int i = paramBigDecimal.toBigInteger().ToString().Length; i = (i + paramInt - 1) / paramInt; if (i > 0) { bigDecimal3 = (new BigDecimalFixed("5")).movePointRight(i - 1); } } sbyte b = 0; do { decimal bigDecimal5 = bigDecimal3; decimal bigDecimal6 = bigDecimal2; for (sbyte b1 = 1; b1 < paramInt; b1++) { bigDecimal6 = bigDecimal6.divide(bigDecimal3, ROUND_DOWN); } bigDecimal3 = mult(bigDecimal3, bigDecimal1) + bigDecimal6; bigDecimal4 = bigDecimal5 - bigDecimal3; } while (bigDecimal4.abs().compareTo(CALC_PRECISION) > 0 && ++b < (sbyte)'✐'); return(bigDecimal3.setScale(32, ROUND_DOWN)); }
public static decimal[] mod(decimal paramBigDecimal1, decimal paramBigDecimal2) { decimal[] arrayOfBigDecimal = new decimal[2]; if (paramBigDecimal2.CompareTo(ZERO) == 0) { return(null); } paramBigDecimal2 = paramBigDecimal2.abs(); decimal bigDecimal1 = div(paramBigDecimal1, paramBigDecimal2); arrayOfBigDecimal[0] = new BigDecimalFixed(bigDecimal1.toBigInteger()); decimal bigDecimal2 = mult(paramBigDecimal2, arrayOfBigDecimal[0]); arrayOfBigDecimal[1] = paramBigDecimal1 - bigDecimal2; return(arrayOfBigDecimal); }
public virtual void reloadVariables() { foreach (string str in BoqItemTable.VIEWABLE_FIELDS) { object @object = getFieldValue(this.assemblyTable, str); if (@object == null && !this.lineItemFields.Contains(str)) { BigDecimalFixed bigDecimalFixed = new BigDecimalFixed(0); DateTime date = DateTime.Now; bool? @bool = false; Type clazz = getReturnType(this.boqItemTable, str); if (clazz != null) { if (clazz.Equals(typeof(decimal))) { this.decimalVariableMap[BoqItemFormulaEvaluator.variableFromField(str)] = bigDecimalFixed; } else if (clazz.Equals(typeof(string))) { this.textVariableMap[BoqItemFormulaEvaluator.variableFromField(str)] = ""; } else if (clazz.Equals(typeof(DateTime))) { this.dateVariableMap[BoqItemFormulaEvaluator.variableFromField(str)] = date; } else if (clazz.Equals(typeof(Boolean))) { this.booleanVariableMap[BoqItemFormulaEvaluator.variableFromField(str)] = @bool.Value; } } } else if (@object is Number) { if (@object is decimal) { this.decimalVariableMap[variableFromField(str)] = (decimal)@object; } else { this.decimalVariableMap[variableFromField(str)] = new BigDecimalFixed(@object.ToString()); } } else if (@object is string) { this.textVariableMap[variableFromField(str)] = (string)@object; } else if (@object is DateTime) { this.dateVariableMap[variableFromField(str)] = (DateTime)@object; } else if (@object is bool?) { this.booleanVariableMap[variableFromField(str)] = (bool?)@object; } else if (@object == null) { this.textVariableMap[variableFromField(str)] = ""; } } this.localVariableMap = LocalVariablesDatabaseUtil.getLocalVariables(this.assemblyTable.Vars); }
public virtual decimal calculateFinalRate() { decimal fRate = finalRate; if (BoqItemTable != null) { decimal tUnits = BigDecimalMath.ONE; tUnits = boqItemTable.Quantity; tUnits = tUnits * Factor1; tUnits = tUnits * Factor2; tUnits = tUnits * Factor3; tUnits = tUnits * QuantityPerUnit; //tUnits = tUnits.multiply(getBoqItemTable().getDuration()); totalUnits = tUnits; } if (MaterialTable != null) { fRate = calculateFinalRateFor(MaterialTable.RateForCalculation); finalShipmentRate = calculateFinalRateFor(MaterialTable.ShipmentRate); finalFabricationRate = calculateFinalRateFor(MaterialTable.FabricationRate); finalMaterialRate = calculateFinalRateFor(MaterialTable.Rate); // Escalation bool isUnspecified = MaterialTable.RawMaterial.Equals(MaterialTable.UNSPECIFIED_RAWMAT); if (isUnspecified) { finalEscalationRate = BigDecimalMath.ZERO; } else { decimal esc = BigDecimalMath.ONE.subtract(Escalation); decimal reliance = new BigDecimalFixed("" + MaterialTable.RawMaterialReliance.doubleValue() / 100D); decimal materialRate = fRate * reliance; finalEscalationRate = materialRate * esc; finalEscalationRate = materialRate - finalEscalationRate; // FULL FORMULA: // materialRate = materialUnitRate*factor1*factor2/divider*exchangeRate*reliance // finalEscalationRate = materialRate-(materialRate*(1 - escalationFactor)) // totalEscalationCost = finalEscalationRate*quantity // escalationCost = SUM(totalEscalationCost) } if (BoqItemTable != null) { // Calculate Variable, Total Cost: variableCost = fRate * (BoqItemTable.Quantity); totalCost = decimal.Zero; totalCost = totalCost + variableCost; totalCost = totalCost + FinalFixedCost; // Avoid precision/scale updates if data is the same: variableCost = variableCost.setScale(10, decimal.ROUND_HALF_UP); totalShipmentCost = finalShipmentRate * (BoqItemTable.Quantity); totalFabricationCost = finalFabricationRate * (BoqItemTable.Quantity); totalEscalationCost = finalEscalationRate * (BoqItemTable.Quantity); totalMaterialCost = finalMaterialRate * (BoqItemTable.Quantity); // Avoid precision/scale updates if data is the same: fRate = fRate.setScale(10, decimal.ROUND_HALF_UP); finalShipmentRate = finalShipmentRate.setScale(10, decimal.ROUND_HALF_UP); finalFabricationRate = finalFabricationRate.setScale(10, decimal.ROUND_HALF_UP); finalEscalationRate = finalEscalationRate.setScale(10, decimal.ROUND_HALF_UP); finalMaterialRate = finalMaterialRate.setScale(10, decimal.ROUND_HALF_UP); totalCost = totalCost.setScale(10, decimal.ROUND_HALF_UP); totalShipmentCost = totalShipmentCost.setScale(10, decimal.ROUND_HALF_UP); totalFabricationCost = totalFabricationCost.setScale(10, decimal.ROUND_HALF_UP); totalEscalationCost = totalEscalationCost.setScale(10, decimal.ROUND_HALF_UP); totalMaterialCost = totalMaterialCost.setScale(10, decimal.ROUND_HALF_UP); totalUnits = totalUnits.setScale(10, decimal.ROUND_HALF_UP); } } finalRate = fRate; return(fRate); }