当前位置: 首页>>代码示例>>C#>>正文


C# Money.ToString方法代码示例

本文整理汇总了C#中Money.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Money.ToString方法的具体用法?C# Money.ToString怎么用?C# Money.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Money的用法示例。


在下文中一共展示了Money.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestCreationOfBasicMoney

		public void TestCreationOfBasicMoney()
		{
            var currentSymbol = CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol;
            var currentRegion = new RegionInfo(CultureInfo.CurrentCulture.LCID);
            var currentCode = currentRegion.ISOCurrencySymbol;
            var currentEnglishName = currentRegion.CurrencyEnglishName;
            var currentDigits = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits;

            //Locale specific formatting
            var money1 = new Money(2000.1234567m, CurrencyCodes.USD);
			Assert.AreEqual("$2,000.12", money1.ToString());

			//Default currency
			var money2 = new Money(3000m);
			Assert.AreEqual(currentCode, money2.CurrencyCode);
			Assert.AreEqual(currentSymbol, money2.CurrencySymbol);
			Assert.AreEqual(currentEnglishName, money2.CurrencyName);
			Assert.AreEqual(currentDigits, money2.DecimalDigits);

			//Implicit casting of int, decimal and double to Money
			var money3 = new Money(5.0d);
			var money4 = new Money(5.0m);
			var money5 = new Money(5);
			Money money6 = 5.0d;
			Money money7 = 5.0m;
			Money money8 = 5;
			Money money9 = 5.0f;
			Money money10 = 5.0;
			Assert.IsTrue(money3 == money4 && money4 == money5 && money5 == money6 && money6 == money7 && money7 == money8 && money8 == money9 && money9 == money10);

			//Generic 3char currency code formatting instead of locale based with symbols
			Assert.AreEqual("USD2,000", money1.ToString(true));

		}
开发者ID:Padhraic,项目名称:Utile.Money,代码行数:34,代码来源:MoneyTest.cs

示例2: Money

        /// <summary>
        /// Formats the price based on the shop's HTML without currency setting.
        /// {{ 145 | money }}
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string Money(object input)
        {
            if (input == null)
            {
                return null;
            }
            var themeEngine = (ShopifyLiquidThemeEngine)Template.FileSystem;
            var amount = Convert.ToDecimal(input, CultureInfo.InvariantCulture);
            var money = new Money(amount / 100, themeEngine.WorkContext.CurrentCurrency.Code);

            return money.ToString();
        }
开发者ID:adwardliu,项目名称:vc-community,代码行数:18,代码来源:MoneyFilters.cs

示例3: GetShippingMethodName

        /// <summary>
        ///     Gets display name of shipping method
        /// </summary>
        /// <returns></returns>
        private string GetShippingMethodName()
        {
            var shippingMethodDto = ShippingManager.GetShippingMethod(Shipment.ShippingMethodId, true);
            if (shippingMethodDto != null && shippingMethodDto.ShippingMethod.Count > 0)
            {
                var shippingMethod = shippingMethodDto.ShippingMethod[0];

                Money currentPrice = new Money(Shipment.ShipmentTotal, BillingCurrency);

                return string.Format("{0} - {1}", shippingMethod.DisplayName.ToHtmlEncode(), currentPrice.ToString());
            }
            return string.Empty;
        }
开发者ID:georgelazar,项目名称:commerce-webforms-sample-owin,代码行数:17,代码来源:ShippingMethodInfo.ascx.cs

示例4: GetTotalCashAmount

        public static void GetTotalCashAmount(int accountId, out string cashPositionString, out string moneyFundPositionString, out string openOrderCashString)
        {
            IDalSession session = NHSessionFactory.CreateSession();
            IAccountTypeCustomer account = (IAccountTypeCustomer)AccountMapper.GetAccount(session, accountId);
            Money totalCashAmount = account.TotalPositionAmount(PositionAmountReturnValue.Cash);
            Money moneyFundAmount = account.TotalPositionAmount(PositionAmountReturnValue.CashFund);
            Money zeroAmount = new Money(0M, account.BaseCurrency);

            if (totalCashAmount != null)
                cashPositionString = totalCashAmount.ToString();
            else
                cashPositionString = zeroAmount.ToString();
            if (moneyFundAmount != null)
                moneyFundPositionString = moneyFundAmount.ToString();
            else
                moneyFundPositionString = zeroAmount.ToString();
            if (account.OpenOrderAmount() != null)
                openOrderCashString = account.OpenOrderAmount().ToString();
            else
                openOrderCashString = zeroAmount.ToString();

            session.Close();
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:23,代码来源:SingleOrderAdapter.cs

示例5: MoneyMoney

        public void MoneyMoney()
        {
            Money m1 = new Money();
            Money m2 = new Money(25,51);
            Money m3 = new Money(1024);

            int hrivnas = m1.Hrivnas;
            int kopecks = m1.Kopecks;

            Money m4 = m1 + m3;
            int totalKopecs = (int)m2;
            float someMoney = (float)m2;
            string moneyString = (string)m2;
            string moneyString1 = m2.ToString();
        }
开发者ID:vbre,项目名称:tasks_cs2,代码行数:15,代码来源:EncapsulationExercises.cs

示例6: TestSignificantDecimalDigits

        public void TestSignificantDecimalDigits()
        {
            var money1 = new Money(13000123.3349m, CurrencyCodes.USD);
            Assert.AreEqual("$13,000,123.33", money1.ToString());
            // Can also use CurrencyCode string (catch code not found exception)
            var money2 = new Money(13000123.335m, CurrencyCodes.USD);
            Assert.AreEqual("$13,000,123.34", money2.ToString());

            // Test Amount rounding
            var money3 = new Money(1.001m, CurrencyCodes.ZAR) ;
            Assert.AreEqual(0.40m, (money3 * 0.404).Amount);
            Assert.AreEqual(0.41m, (money3 * 0.40501).Amount);
            Assert.AreEqual(0.41m, (money3 * 0.404999999999999).Amount);
            money3 = new Money(1.0, CurrencyCodes.ZAR);
            Assert.AreEqual(0.40m, (money3 * 0.404999999999999).Amount);

            //Different significant digits
            var money4 = new Money(2.499m, CurrencyCodes.USD);
            Assert.AreEqual("$2.50", money4.ToString());

            var money5 = new Money(2.499m, CurrencyCodes.JPY);
            Assert.AreEqual("¥2", money5.ToString());

            //Very large numbers
            //Double is used internally, only 16 digits of accuracy can be guaranteed
            var money6 = new Money(123456789012.34, CurrencyCodes.ZAR); //14 digits
            money6 *= 1.14; //will add another 2 digits of detail
            money6 /= 1.14;
            Assert.AreEqual(money6.Amount, 123456789012.34m);

            var money7 = new Money(23.99999999m,CurrencyCodes.JPY);
            Assert.AreEqual(23m, money7.TruncatedAmount);
            var money8 = new Money(23.99999999m, CurrencyCodes.AUD);
            Assert.AreEqual(23.99m, money8.TruncatedAmount);
            var money9 = new Money(23.99999999m, CurrencyCodes.BHD);
            Assert.AreEqual(23.999m, money9.TruncatedAmount);


        }
开发者ID:Padhraic,项目名称:Utile.Money,代码行数:39,代码来源:MoneyTest.cs

示例7: addFixMinMax

        protected Money addFixMinMax(Money fee, ICommClient client)
        {
            // Add Fixed setup
            if (FixedSetup != null && FixedSetup.IsNotZero)
            {
                fee += FixedSetup;
                SetCommissionInfoOnOrder(client, string.Format("Add setup {0}", FixedSetup.ToString()));
            }

            // Check Minimum Value
            if (MinValue != null && MinValue.IsNotZero && fee < MinValue)
            {
                // Extra check -> does the minimum size not exceed the order value
                Money orderAmount = client.Amount;
                if (orderAmount != null && orderAmount.IsNotZero)
                {
                    orderAmount = orderAmount.Abs();
                    if (!orderAmount.Underlying.Equals(this.CommCurrency))
                        orderAmount = orderAmount.Convert(this.CommCurrency);

                    if (orderAmount > fee)
                    {
                        fee = MinValue;
                        SetCommissionInfoOnOrder(client, string.Format("Calculated commission {0} is smaller than minimum value {1}", fee.ToString(), MinValue.ToString()));
                    }
                    else
                        SetCommissionInfoOnOrder(client, string.Format("Order amount {0} is smaller than minimum value of the commission {1}, so it is not applied", orderAmount.ToString(), MinValue.ToString()));
                }
            }

            // Check Maximum Value
            if (MaxValue != null && MaxValue.IsNotZero && fee > MaxValue)
            {
                SetCommissionInfoOnOrder(client, string.Format("Calculated commission {0} exceeds the maximum value {1}", fee.ToString(), MaxValue.ToString()));
                fee = MaxValue;
            }
            return fee;
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:38,代码来源:CommCalc.cs

示例8: DustPolicyError

		public DustPolicyError(Money value, Money dust)
			: base("Dust output detected, output value is " + value.ToString() + ", policy minimum is " + dust.ToString())
		{
			_Value = value;
			_DustThreshold = dust;
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:6,代码来源:ITransactionPolicy.cs

示例9: FeeTooHighPolicyError

		public FeeTooHighPolicyError(Money fees, Money max)
			: base("Fee too high, actual is " + fees.ToString() + ", policy maximum is " + max.ToString())
		{
			_ExpectedMaxFee = max;
			_Fee = fees;
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:6,代码来源:ITransactionPolicy.cs

示例10: FeeTooLowPolicyError

		public FeeTooLowPolicyError(Money fees, Money min)
			: base("Fee too low, actual is " + fees.ToString() + ", policy minimum is " + min.ToString())
		{
			_ExpectedMinFee = min;
			_Fee = fees;
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:6,代码来源:ITransactionPolicy.cs

示例11: Money_ToString

        public void Money_ToString()
        {
            var money1 = new Money(50);
            var money2 = new Money(50.01M);
            var money3 = new Money(-50.01M);

            Assert.Equal("50.00", money1.ToString());
            Assert.Equal("50.01", money2.ToString());
            Assert.Equal("-50.01", money3.ToString());
        }
开发者ID:kcornelis,项目名称:FreelanceManager.NET,代码行数:10,代码来源:MoneyTests.cs

示例12: Can_sum

        public void Can_sum()
        {
            var monies = new List<Money>();
            for (var i = 0; i < 10; i++)
            {
                monies.Add(new Money(1.45m));
            }
            var value = new Money(0);
            foreach (var money in monies)
            {
                value += money;
            }

            Console.WriteLine(value.ToString()); // Outputs 14, but is actually stored internally as $14.50
        }
开发者ID:jtpatil,项目名称:webstack,代码行数:15,代码来源:MoneyTests.cs

示例13: ToStringReturnsFormattedMoneyAmount

 public void ToStringReturnsFormattedMoneyAmount()
 {
     const decimal amount = (decimal)45.87;
     Money money = new Money(amount, CurrencyFixture.NewZealandDollar);
     Assert.AreEqual("$45.87", money.ToString());
 }
开发者ID:jonocairns,项目名称:csharp-money,代码行数:6,代码来源:MoneyTest.cs

示例14: TestAllocation

		public void TestAllocation()
		{
			var money1 = new Money(10, CurrencyCodes.ZAR);
			var allocatedMoney1 = money1.Allocate(3);
			var total1 = new Money(CurrencyCodes.ZAR);

		    total1 = allocatedMoney1.Aggregate(total1, (current, t) => current + t);
		    Assert.AreEqual("R10,00", total1.ToString());
			Assert.AreEqual("R3,34", allocatedMoney1[0].ToString());
			Assert.AreEqual("R3,33", allocatedMoney1[1].ToString());
			Assert.AreEqual("R3,33", allocatedMoney1[2].ToString());

			var money2 = new Money(0.09m, CurrencyCodes.USD);
			var allocatedMoney2 = money2.Allocate(5);
			var total2 = new Money(CurrencyCodes.USD);
		    total2 = allocatedMoney2.Aggregate(total2, (current, t) => current + t);
		    Assert.AreEqual("$0.09", total2.ToString());
		}
开发者ID:Padhraic,项目名称:Utile.Money,代码行数:18,代码来源:MoneyTest.cs

示例15: SendToAddressAsync

		/// <summary>
		/// Requires wallet support. Requires an unlocked wallet or an unencrypted wallet.
		/// </summary>
		/// <param name="address">A P2PKH or P2SH address to which the bitcoins should be sent</param>
		/// <param name="amount">The amount to spend</param>
		/// <param name="commentTx">A locally-stored (not broadcast) comment assigned to this transaction. Default is no comment</param>
		/// <param name="commentDest">A locally-stored (not broadcast) comment assigned to this transaction. Meant to be used for describing who the payment was sent to. Default is no comment</param>
		/// <returns>The TXID of the sent transaction</returns>
		public async Task<uint256> SendToAddressAsync(BitcoinAddress address, Money amount, string commentTx = null, string commentDest = null)
		{
			List<object> parameters = new List<object>();
			parameters.Add(address.ToString());
			parameters.Add(amount.ToString());
			if(commentTx != null)
				parameters.Add(commentTx);
			if(commentDest != null)
				parameters.Add(commentDest);
			var resp = await SendCommandAsync(RPCOperations.sendtoaddress, parameters.ToArray()).ConfigureAwait(false);
			return uint256.Parse(resp.Result.ToString());
		}
开发者ID:crowar,项目名称:NBitcoin,代码行数:20,代码来源:RPCClient.cs


注:本文中的Money.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。