public Money(Currency currency, decimal amount, RoundingMode roundingMode, DecimalPlaces decimalPlaces) { Currency = currency; Amount = amount; RoundingMode = roundingMode; DecimalPlaces = (int)decimalPlaces; }
protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (localContext == null) { throw new ArgumentNullException(nameof(localContext)); } decimal numberToTruncate = NumberToTruncate.Get(context); int decimalPlaces = DecimalPlaces.Get(context); if (decimalPlaces < 0) { decimalPlaces = 0; } decimal step = (decimal)Math.Pow(10, decimalPlaces); int temp = (int)Math.Truncate(step * numberToTruncate); decimal truncatedNumber = temp / step; TruncatedNumber.Set(context, truncatedNumber); }
/// <include file='doc\NumericUpDown.uex' path='docs/doc[@for="NumericUpDown.UpdateEditText"]/*' /> /// <devdoc> /// <para> /// Displays the current value of the up-down control in the appropriate format. /// </para> /// </devdoc> protected override void UpdateEditText() { // If we're initializing, we don't want to update the edit text yet, // just in case the value is invalid. if (initializing) { return; } // If the current value is user-edited, then parse this value before reformatting if (UserEdit) { ParseEditText(); } ChangingText = true; // Make sure the current value is within the min/max Debug.Assert(minimum <= currentValue && currentValue <= maximum, "DecimalValue lies outside of [minimum, maximum]"); if (Hexadecimal) { Text = ((Int64)currentValue).ToString("X"); } else { Text = currentValue.ToString((ThousandsSeparator ? "N" : "F") + DecimalPlaces.ToString()); } Debug.Assert(ChangingText == false, "ChangingText should have been set to false"); }
public virtual void ToXml(XmlWriter writer) { var numberFormatEnumConverter = TypeDescriptor.GetConverter(typeof(NumberFormatEnum)); writer.WriteAttributeString("visible", Visible.ToString()); writer.WriteAttributeString("decimalplaces", DecimalPlaces.ToString()); writer.WriteAttributeString("numberformat", numberFormatEnumConverter.ConvertToString(NumberFormat)); }
public void Round_DecimalPlaces_using_Money_RoundingMode(RoundingMode roundingMode, DecimalPlaces decimalPlaces, decimal value, decimal expected) { // specify different DecimalPlaces for Money ctor to ensure the argument value is used Money money = new Money("ZAR", value, roundingMode, DecimalPlaces.Nine); Money actual = money.Round(decimalPlaces); Assert.That(actual.Amount == expected); }
public void Round_RoundingMode_using_Money_DecimalPlaces(RoundingMode roundingMode, DecimalPlaces decimalPlaces, decimal value, decimal expected) { // specify different RoundingMode for Money ctor to ensure the argument value is used RoundingMode moneyMode = roundingMode == 0 ? roundingMode + 1 : roundingMode - 1; Money money = new Money("ZAR", value, moneyMode, decimalPlaces); Money actual = money.Round(roundingMode); Assert.That(actual.Amount == expected); }
private string GetNumberText(decimal num) { string text; if (Hexadecimal) { text = ((Int64)num).ToString("X", CultureInfo.InvariantCulture); Debug.Assert(text == text.ToUpper(CultureInfo.InvariantCulture), "GetPreferredSize assumes hex digits to be uppercase."); } else { text = num.ToString((ThousandsSeparator ? "N" : "F") + DecimalPlaces.ToString(CultureInfo.CurrentCulture), CultureInfo.CurrentCulture); } return text; }
public void Round_DecimalPlaces_RoundingMode(RoundingMode roundingMode, DecimalPlaces decimalPlaces, decimal value, decimal expected) { // specify different RoundingMode for Money ctor to ensure the argument value is used RoundingMode moneyMode = roundingMode == 0 ? roundingMode + 1 : roundingMode - 1; // specify different DecimalPlaces for Money ctor to ensure the argument value is used Money money = new Money("ZAR", value, moneyMode, DecimalPlaces.Nine); Money actual = money.Round(roundingMode, decimalPlaces); Assert.That(actual.Amount == expected); }
/// <summary> /// Add a JavaScript to the Page and call it from the onKeyPress event /// </summary> /// <param name="e"></param> override protected void OnPreRender(EventArgs e) { if (this.Page.Request.Browser.JavaScript == true) { // Build JavaScript StringBuilder s = new StringBuilder(); s.Append("\n<script type='text/javascript' language='JavaScript'>\n"); s.Append("<!--\n"); s.Append(" function NumberBoxKeyPress(event, dp, dc, n) {\n"); s.Append(" var myString = new String(event.srcElement.value);\n"); s.Append(" var pntPos = myString.indexOf(String.fromCharCode(dc));\n"); s.Append(" var keyChar = window.event.keyCode;\n"); s.Append(" if ((keyChar < 48) || (keyChar > 57)) {\n"); s.Append(" if (keyChar == dc) {\n"); s.Append(" if ((pntPos != -1) || (dp < 1)) {\n"); s.Append(" return false;\n"); s.Append(" }\n"); s.Append(" } else \n"); s.Append("if (((keyChar == 45) && (!n || myString.length != 0)) || (keyChar != 45)) \n"); s.Append(" return false;\n"); s.Append(" }\n"); s.Append(" return true;\n"); s.Append(" }\n"); s.Append("// -->\n"); s.Append("</script>\n"); // Add the Script to the Page this.Page.RegisterClientScriptBlock("NumberBoxKeyPress", s.ToString()); // Add KeyPress Event try { this.Attributes.Remove("onKeyPress"); } finally { this.Attributes.Add("onKeyPress", "return NumberBoxKeyPress(event, " + DecimalPlaces.ToString() + ", " + ((int)DecimalSymbol).ToString() + ", " + AllowNegatives.ToString().ToLower() + ")"); } } }
/// <summary> /// Converts the numeric value of this instance to its equivalent string representation . /// </summary> /// <param name="value">The value to be converted.</param> /// <param name="resolution">The number of decimal places.</param> /// <returns> /// The string representation of the numeric value /// </returns> public static string ToString(this double value, DecimalPlaces resolution) { if (double.IsNaN(value)) { return(NaN_Representation); } if (double.IsInfinity(value)) { return(Infinity_Representation); } if (resolution == DecimalPlaces.All) { return(value.ToString(CultureInfo.CurrentCulture)); } NumberFormat.NumberDecimalDigits = (int)resolution; return(value.ToString("N", NumberFormat)); }
/// <summary> /// Serves as a hash function for a particular type. /// </summary> /// <returns>A hash code for the current object.</returns> public override int GetHashCode() { unchecked { int result = 17; result = result * 23 + base.GetHashCode(); result = result * 23 + ((Name != null) ? Name.GetHashCode() : 0); result = result * 23 + Type.GetHashCode(); result = result * 23 + Editable.GetHashCode(); result = result * 23 + Mandatory.GetHashCode(); result = result * 23 + Hidden.GetHashCode(); result = result * 23 + Hideable.GetHashCode(); result = result * 23 + Width.GetHashCode(); result = result * 23 + ((Text != null) ? Text.GetHashCode() : 0); result = result * 23 + Xtype.GetHashCode(); result = result * 23 + Align.GetHashCode(); result = result * 23 + ((Tooltip != null) ? Tooltip.GetHashCode() : 0); result = result * 23 + Sortable.GetHashCode(); result = result * 23 + SortDirection.GetHashCode(); result = result * 23 + ((Format != null) ? Format.GetHashCode() : 0); result = result * 23 + DecimalPlaces.GetHashCode(); result = result * 23 + ((DataUrl != null) ? DataUrl.GetHashCode() : 0); result = result * 23 + ((DefaultValue != null) ? DefaultValue.GetHashCode() : 0); result = result * 23 + ((Description != null) ? Description.GetHashCode() : 0); result = result * 23 + Rank.GetHashCode(); result = result * 23 + ReadOnly.GetHashCode(); result = result * 23 + MaxLength.GetHashCode(); result = result * 23 + ((Validator != null) ? Validator.GetHashCode() : 0); result = result * 23 + ((SearchFieldDefinition != null) ? SearchFieldDefinition.GetHashCode() : 0); result = result * 23 + SingleComboFilter.GetHashCode(); result = result * 23 + AllowComboCustomValue.GetHashCode(); result = result * 23 + SearchComboFromLeft.GetHashCode(); result = result * 23 + LoadWhenVisible.GetHashCode(); result = result * 23 + Nullable.GetHashCode(); result = result * 23 + ((Tpl != null) ? Tpl.GetHashCode() : 0); result = result * 23 + MinCharSearch.GetHashCode(); result = result * 23 + ((AdditionalWhereSqlTemp != null) ? AdditionalWhereSqlTemp.GetHashCode() : 0); return(result); } }
protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (localContext == null) { throw new ArgumentNullException(nameof(localContext)); } decimal numberToRound = NumberToRound.Get(context); int decimalPlaces = DecimalPlaces.Get(context); if (decimalPlaces < 0) { decimalPlaces = 0; } decimal roundedNumber = Math.Round(numberToRound, decimalPlaces); RoundedNumber.Set(context, roundedNumber); }
public override string ToString() { StringBuilder sb = new StringBuilder(); sb.AppendFormat("纸币器级别:{0}\r\n", level.ToString()); sb.AppendFormat("货币代码:{0}\r\n", CC.ToString()); sb.AppendFormat("纸币基数值:{0}\r\n", BillScalingFacto.ToString()); sb.AppendFormat("小数点位数:{0}\r\n", DecimalPlaces.ToString()); sb.AppendFormat("钞箱容量:{0}\r\n", 钞箱容量.ToString()); sb.AppendFormat("安全等级:{0}\r\n", 安全等级.ToString()); sb.AppendFormat("暂存功能:{0}\r\n", (暂存功能 ? "有" : "无")); sb.AppendFormat("纸币1基数:{0}\r\n", 纸币1.ToString()); sb.AppendFormat("纸币2基数:{0}\r\n", 纸币2.ToString()); sb.AppendFormat("纸币3基数:{0}\r\n", 纸币3.ToString()); sb.AppendFormat("纸币4基数:{0}\r\n", 纸币4.ToString()); sb.AppendFormat("纸币5基数:{0}\r\n", 纸币5.ToString()); sb.AppendFormat("纸币6基数:{0}\r\n", 纸币6.ToString()); sb.AppendFormat("纸币7基数:{0}\r\n", 纸币7.ToString()); sb.AppendFormat("纸币8基数:{0}\r\n", 纸币8.ToString()); sb.AppendFormat("Identification:{0}\r\n", Z.ToString()); return(sb.ToString()); }
public override string ToString() { StringBuilder sb = new StringBuilder(); sb.AppendFormat("硬币器级别:{0}\r\n", level.ToString()); sb.AppendFormat("硬币代码:{0}\r\n", CC.ToString()); sb.AppendFormat("硬币基数值:{0}\r\n", CoinScalingFacto.ToString()); sb.AppendFormat("小数点位数:{0}\r\n", DecimalPlaces.ToString()); sb.AppendFormat("硬币1基数:{0}\r\n", 硬币1.ToString()); sb.AppendFormat("硬币2基数:{0}\r\n", 硬币2.ToString()); sb.AppendFormat("硬币3基数:{0}\r\n", 硬币3.ToString()); sb.AppendFormat("硬币4基数:{0}\r\n", 硬币4.ToString()); sb.AppendFormat("硬币5基数:{0}\r\n", 硬币5.ToString()); sb.AppendFormat("硬币6基数:{0}\r\n", 硬币6.ToString()); sb.AppendFormat("找零1:{0}\r\n", 找零1.ToString()); sb.AppendFormat("找零2:{0}\r\n", 找零2.ToString()); sb.AppendFormat("找零3:{0}\r\n", 找零3.ToString()); sb.AppendFormat("找零4:{0}\r\n", 找零4.ToString()); sb.AppendFormat("找零5:{0}\r\n", 找零5.ToString()); sb.AppendFormat("找零6:{0}\r\n", 找零6.ToString()); sb.AppendFormat("Identification:{0}\r\n", Z.ToString()); return(sb.ToString()); }
public static Money Round(this Money money, RoundingMode roundingMode, DecimalPlaces decimalPlaces) { RoundingStrategy strategy = RoundingStrategyFactory.GetRoundingStrategy(roundingMode); return(strategy.Round(money, (int)decimalPlaces)); }
public void DecimalPlacesSimpleTest_01() { Assert.AreEqual(10.12, DecimalPlaces.TwoDecimalPlaces(10.1289767789)); }
public void Round_no_arguments_using_Money_defaults(RoundingMode roundingMode, DecimalPlaces decimalPlaces, decimal value, decimal expected) { Money money = new Money("ZAR", value, roundingMode, decimalPlaces); Money actual = money.Round(); Assert.That(actual.Amount == expected); }
public void DecimalPlacesSimpleTest_Negative_02() { Assert.AreEqual(-7488.83, DecimalPlaces.TwoDecimalPlaces(-7488.83485834983)); }
public void DecimalPlaces_Test_Random_03([Random(-2837823.73748453445, 2837823.73748453445, 98)] double number) { Assert.AreEqual(this.TwoDecimalPlaces(number), DecimalPlaces.TwoDecimalPlaces(number)); }
public Money(Currency currency, decimal amount, DecimalPlaces decimalPlaces) : this(currency, amount, defaultRoundingMode, decimalPlaces) { }
public Money(string currencyCode, decimal amount, RoundingMode roundingMode, DecimalPlaces decimalPlaces) : this(Currency.FromIso3LetterCode(currencyCode), amount, roundingMode, decimalPlaces) { }
public void Round_no_arguments_using_Money_defaults(RoundingMode roundingMode, DecimalPlaces decimalPlaces, decimal value, decimal expected) { Money money = new Money("ZAR", value, roundingMode, decimalPlaces); Money actual = money.Round(); Assert.That(actual.Amount == expected); }
public static Money Round(this Money money, DecimalPlaces decimalPlaces) { return(money.Round(money.RoundingMode, decimalPlaces)); }
protected override void Render(System.Web.UI.HtmlTextWriter writer) { this.CssClass = "form-control " + this.CssClass; StringBuilder sb = new StringBuilder(); Attributes.Add("autocomplete", AutoComplete ? "on" : "off"); if (this.HasEvent("EventTextChanged")) { this.AutoPostBack = true; } if (Mask != MaskTextBox.NaoDefinido) { if (Mask == MaskTextBox.Decimal || Mask == MaskTextBox.Integer) { Attributes.Add("data-control-allownegative", AllowNegativeValues.ToString()); if (Mask == MaskTextBox.Decimal && DecimalPlaces > 0) { Attributes.Add("data-control-decimalplaces", DecimalPlaces.ToString()); } } this.Attributes.Add("data-control", Mask.ToString()); } if (montagroup) { writer.Write(ComponentUtils.RenderControlOpen(this.campoobrigatorio ? "*" + this.label : this.label, this.ID, TypeControl, TextBoxIcon != FontAwesomeIcons.NotSet, ObrigatorioVazio, ToolTip)); } base.Attributes.Add("data-control-required", campoobrigatorio.ToString()); if (TextBoxIcon != FontAwesomeIcons.NotSet) { writer.Write("<span class=\"input-group-addon\"><i class=\"{0} {1}\"></i></span>", TextBoxIconType.GetStringValueClass(), TextBoxIcon.GetStringValueClass()); base.Render(writer); } else { if (GroupButtons.Count > 0) { writer.Write("<div class='input-group'>"); if (GroupButtons.Count(p => p.ButtonPosition == InputGroupButton.InputGroupButtonPosition.Left) > 0) { writer.Write("<div class='input-group-btn'>"); foreach (var btn in GroupButtons.Where(p => p.ButtonPosition == InputGroupButton.InputGroupButtonPosition.Left)) { btn.RenderControl(writer); } writer.Write("</div>"); } } base.Render(writer); if (GroupButtons.Count > 0) { if (GroupButtons.Count(p => p.ButtonPosition == InputGroupButton.InputGroupButtonPosition.Right) > 0) { writer.Write("<div class='input-group-btn'>"); foreach (var btn in GroupButtons.Where(p => p.ButtonPosition == InputGroupButton.InputGroupButtonPosition.Right)) { btn.RenderControl(writer); } writer.Write("</div>"); } writer.Write("</div>"); } } if (montagroup) { writer.Write(ComponentUtils.RenderControlClose(help, TypeControl, TextBoxIcon != FontAwesomeIcons.NotSet)); } }
public static Money Round(this Money money, DecimalPlaces decimalPlaces) { return money.Round(money.RoundingMode, decimalPlaces); }
public static Money Round(this Money money, RoundingMode roundingMode, DecimalPlaces decimalPlaces) { RoundingStrategy strategy = RoundingStrategyFactory.GetRoundingStrategy(roundingMode); return strategy.Round(money, (int) decimalPlaces); }