Exemple #1
0
        private static double RoundNumber(double d, RoundingPolicy p)
        {
            switch (p.Strategy)
            {
            case RoundingStrategy.Up:
                return(Logic.Round.Up(d, p.Decimals));

            case RoundingStrategy.Down:
                return(Logic.Round.Down(d, p.Decimals));

            case RoundingStrategy.UpByStep:
                return(Logic.Round.UpByStep(d, p.Step));

            case RoundingStrategy.DownByStep:
                return(Logic.Round.DownByStep(d, p.Step));

            case RoundingStrategy.TowardsPositive:
                return(Logic.Round.TowardsPositive(d, p.Decimals));

            case RoundingStrategy.TowardsNegative:
                return(Logic.Round.TowardsNegative(d, p.Decimals));

            default:
                return(Logic.Round.Off(d, p.Decimals, p.Digit));
            }
        }
Exemple #2
0
        public static double Off(double d, RoundingPolicy p)
        {
            switch (p.Strategy)
            {
            case RoundingStrategy.Up: return(Up(d, p.Decimals));

            case RoundingStrategy.Down: return(Down(d, p.Decimals));

            case RoundingStrategy.UpByStep: return(UpByStep(d, p.Step));

            case RoundingStrategy.DownByStep: return(DownByStep(d, p.Step));

            case RoundingStrategy.TowardsPositive: return(TowardsPositive(d, p.Decimals));

            case RoundingStrategy.TowardsNegative: return(TowardsNegative(d, p.Decimals));

            case RoundingStrategy.Common: return(Off(d, p.Decimals, p.Digit));

            default: return(Off(d, p.Decimals, p.Digit));
            }
        }
Exemple #3
0
        public Quantity Round(RoundingPolicy policy)
        {
            var d = RoundNumber(amount, policy);

            return(new Quantity(d, Unit));
        }