コード例 #1
0
            /// <summary>
            /// Standard round to minimal coin/amount.
            /// </summary>
            /// <param name="request">Service request.</param>
            /// <returns>Rounded value.</returns>
            private GetRoundedValueServiceResponse GetRoundedValue(GetRoundedValueServiceRequest request)
            {
                string  currencyCode = request.CurrencyCode;
                decimal currencyUnit = 0.0m;

                if (string.IsNullOrWhiteSpace(currencyCode))
                {
                    var channelConfiguration = request.RequestContext.GetChannelConfiguration();

                    currencyCode = channelConfiguration.Currency;
                }

                RoundingUnitAndMethod unitAndMethod = GetRoundingUnitAndMethod(request.RequestContext, currencyCode, request.UseSalesRounding);

                if (request.NumberOfDecimals != 0)
                {
                    currencyUnit = 1.0M / (decimal)Math.Pow(10, request.NumberOfDecimals);
                }
                else
                {
                    currencyUnit = unitAndMethod.RoundingUnit;
                }

                decimal value = Rounding.RoundToUnit(request.Value, currencyUnit, unitAndMethod.RoundingMethod);

                return(new GetRoundedValueServiceResponse(value));
            }
コード例 #2
0
            /// <summary>
            /// Standard round to minimal coin/amount.
            /// </summary>
            /// <param name="request">Service request.</param>
            /// <returns>Rounded value.</returns>
            private GetRoundedStringServiceResponse GetRoundedString(GetRoundedStringServiceRequest request)
            {
                string  currencyCode = request.CurrencyCode;
                decimal currencyUnit = 0.0m;

                if (string.IsNullOrWhiteSpace(currencyCode))
                {
                    var channelConfiguration = request.RequestContext.GetChannelConfiguration();

                    currencyCode = channelConfiguration.Currency;
                }

                RoundingUnitAndMethod unitAndMethod = GetRoundingUnitAndMethod(request.RequestContext, currencyCode, request.UseSalesRounding);

                if (request.NumberOfDecimals != 0)
                {
                    currencyUnit = 1.0M / (decimal)Math.Pow(10, request.NumberOfDecimals);
                }
                else
                {
                    currencyUnit = unitAndMethod.RoundingUnit;
                }

                string  format = NumberFormat(currencyUnit);
                decimal value;

                value = !request.IsRounded
                    ? Rounding.RoundToUnit(request.Value, currencyUnit, unitAndMethod.RoundingMethod)
                    : request.Value;

                string roundedString = value.ToString(format, CultureInfo.InvariantCulture);

                return(new GetRoundedStringServiceResponse(roundedString));
            }