/// <summary>
        /// Return the percent the fraction is of the base value.
        /// </summary>
        /// <returns>When the base value is zero, returns zero.</returns>
        public static float Percent(float fraction, float baseValue, PercentMode percentMode = PercentMode.AnyPercent)
        {
            if (baseValue == 0f)
            {
                return(0f);
            }
            else
            {
                float percentage = fraction / baseValue;

                switch (percentMode)
                {
                case PercentMode.ClampPositive:
                    return(ClampPositive(percentage));

                case PercentMode.ClampNegative:
                    return(ClampNegative(percentage));

                case PercentMode.Clamp0To1:
                    return(Clamp0To1(percentage));

                case PercentMode.ClampNegative1To1:
                    return(ClampNegative1To1(percentage));

                case PercentMode.ClampNegative1To0:
                    return(ClampNegative1To0(percentage));

                default:
                    // Any percent
                    return(percentage);
                }
            }
        }
 public float ToFloat(PercentMode mode)
 {
     switch (mode)
     {
         case PercentMode.Default:
             return _value;
         case PercentMode.ZeroOne:
             return _value/100f;
         default:
             throw new ArgumentOutOfRangeException(nameof(mode));
     }
 }
 public Percentage(float percent, PercentMode mode)
 {
     switch (mode)
     {
         case PercentMode.Default:
             _value = (int)percent;
             break;
         case PercentMode.ZeroOne:
             _value = (int) (percent*100);
             break;
         default:
             throw new ArgumentOutOfRangeException(nameof(mode));
     }
     Validate();
 }
 public Percentage(double percent, PercentMode mode)
     : this((float)percent, mode)
 {
 }