Example #1
0
 public void Initialize(string name, Image icon, double amount, RoundingBehaviour rounding)
 {
     NameLabel.Text = name;
     if (icon != null && iconBox.Image == null)  // without this line, setting iconBox.Image causes another repaint, hence an infinite loop
         iconBox.Image = icon;
     ValueMB = Util.ToMB(amount, rounding);
     setSpinnerValueDisplay(amount);
     initializing = false;
 }
 public void Initialize(string name, Image icon, double amount, RoundingBehaviour rounding)
 {
     NameLabel.Text = name;
     if (icon != null && iconBox.Image == null)  // without this line, setting iconBox.Image causes another repaint, hence an infinite loop
     {
         iconBox.Image = icon;
     }
     ValueMB = Util.ToMB(amount, rounding);
     setSpinnerValueDisplay(amount);
     initializing = false;
 }
Example #3
0
        public void Initialize(string name, Image icon, long amount, RoundingBehaviour rounding)
        {
            NameLabel.Text = name;
            if (icon != null && iconBox.Image == null)  // without this line, setting iconBox.Image causes another repaint, hence an infinite loop
            {
                iconBox.Image = icon;
            }
            long amountMB = Util.ToMB(amount, rounding);

            Spinner.Value = amountMB;
        }
Example #4
0
        public static long ToMB(long bytes, RoundingBehaviour rounding)
        {
            switch (rounding)
            {
            case RoundingBehaviour.Up:
                return((long)Math.Ceiling((double)(((double)bytes) / 1048576.0)));

            case RoundingBehaviour.Down:
                return((long)Math.Floor((double)(((double)bytes) / 1048576.0)));
            }
            return((long)Math.Round((double)(((double)bytes) / 1048576.0), MidpointRounding.AwayFromZero));
        }
Example #5
0
        public static long ToMB(long bytes, RoundingBehaviour rounding)
        {
            switch (rounding)
            {
            case RoundingBehaviour.Down:
                return((long)Math.Floor(bytes / (double)BINARY_MEGA));

            case RoundingBehaviour.Up:
                return((long)Math.Ceiling(bytes / (double)BINARY_MEGA));

            default:      // case RoundingBehaviour.Nearest:
                return((long)Math.Round(bytes / (double)BINARY_MEGA, MidpointRounding.AwayFromZero));
            }
        }
Example #6
0
        public static double ToGB(double bytes, int dp, RoundingBehaviour rounding)
        {
            double value = (double)bytes / BINARY_GIGA;
            int    decimalsAdjustment = (int)Math.Pow(10, dp);

            switch (rounding)
            {
            case RoundingBehaviour.None:
                return(value);

            case RoundingBehaviour.Down:
                return(Math.Floor(value * decimalsAdjustment) / decimalsAdjustment);

            case RoundingBehaviour.Up:
                return(Math.Ceiling(value * decimalsAdjustment) / decimalsAdjustment);

            default:      // case RoundingBehaviour.Nearest:
                return(Math.Round(value, 1, MidpointRounding.AwayFromZero));
            }
        }
Example #7
0
        private static double DecimalAdjustment(double value, RoundingBehaviour rounding, int decimalPlaces)
        {
            int decimalsAdjustment = (int)Math.Pow(10, decimalPlaces);

            switch (rounding)
            {
            case RoundingBehaviour.None:
                return(value);

            case RoundingBehaviour.Down:
                return(Math.Floor(value * decimalsAdjustment) / decimalsAdjustment);

            case RoundingBehaviour.Up:
                return(Math.Ceiling(value * decimalsAdjustment) / decimalsAdjustment);

            case RoundingBehaviour.Nearest:
            default:
                return(Math.Round(value, decimalPlaces, MidpointRounding.AwayFromZero));
            }
        }
Example #8
0
        public static double ToMB(double bytes, RoundingBehaviour rounding, int decimalPlaces = 0)
        {
            double value = bytes / BINARY_MEGA;

            return(DecimalAdjustment(value, rounding, decimalPlaces));
        }
Example #9
0
 public void Initialize(double amount, RoundingBehaviour rounding)
 {
     ValueMB = Util.ToMB(amount, rounding);
     setSpinnerValueDisplay(amount);
     initializing = false;
 }
Example #10
0
 public void Initialize(string name, Image icon, long amount, RoundingBehaviour rounding)
 {
     NameLabel.Text = name;
     if (icon != null && iconBox.Image == null)  // without this line, setting iconBox.Image causes another repaint, hence an infinite loop
         iconBox.Image = icon;
     long amountMB = Util.ToMB(amount, rounding);
     Spinner.Value = amountMB;
 }