예제 #1
0
파일: SIPrefixes.cs 프로젝트: razaraz/Pscx
        public static String ToString(Double value, SIUnit unit, String format, IFormatProvider formatProvider)
        {
            var unitStr = unit.Symbol;

            if (value != 0)
            {
                var scale = 0;
                var log10 = Math.Log10(value);

                if (log10 < 0)
                {
                    value = MakeLarger(value, unit, out scale);
                }
                else if (log10 > 0)
                {
                    value = MakeSmaller(value, unit, out scale);
                }

                if (scale != 0)
                {
                    unitStr = Prefixes[scale].Symbol + unit.Symbol;
                }
            }

            return String.Format(formatProvider, "{0} {1}", value, unitStr);
        }
예제 #2
0
        public static String ToString(Double value, SIUnit unit, String format, IFormatProvider formatProvider)
        {
            var unitStr = unit.Symbol;

            if (value != 0)
            {
                var scale = 0;
                var log10 = Math.Log10(value);

                if (log10 < 0)
                {
                    value = MakeLarger(value, unit, out scale);
                }
                else if (log10 > 0)
                {
                    value = MakeSmaller(value, unit, out scale);
                }

                if (scale != 0)
                {
                    unitStr = Prefixes[scale].Symbol + unit.Symbol;
                }
            }

            return(String.Format(formatProvider, "{0} {1}", value, unitStr));
        }
예제 #3
0
파일: SIPrefixes.cs 프로젝트: razaraz/Pscx
        private static Double MakeLarger(Double value, SIUnit unit, out Int32 scale)
        {
            var result = value;
            scale = 0;

            foreach (var prefix in unit.NegativePrefixes)
            {
                if (Math.Log10(result) >= 0)
                {
                    return result;
                }

                result = Math.Pow(10, -prefix) * value;
                scale = prefix;
            }

            return result;
        }
예제 #4
0
        private static Double MakeLarger(Double value, SIUnit unit, out Int32 scale)
        {
            var result = value;

            scale = 0;

            foreach (var prefix in unit.NegativePrefixes)
            {
                if (Math.Log10(result) >= 0)
                {
                    return(result);
                }

                result = Math.Pow(10, -prefix) * value;
                scale  = prefix;
            }

            return(result);
        }
예제 #5
0
파일: SIPrefixes.cs 프로젝트: nickchal/pash
        private static Double MakeSmaller(Double value, SIUnit unit, out Int32 scale)
        {
            var result = value;
            scale = 0;

            foreach (var prefix in unit.PositivePrefixes)
            {
                var log10 = Math.Log10(result);

                if ((log10 <= 2) || (log10 < prefix))
                {
                    return result;
                }

                result = Math.Pow(10, -prefix) * value;
                scale = prefix;
            }

            return result;
        }
예제 #6
0
        private static Double MakeSmaller(Double value, SIUnit unit, out Int32 scale)
        {
            var result = value;

            scale = 0;

            foreach (var prefix in unit.PositivePrefixes)
            {
                var log10 = Math.Log10(result);

                if ((log10 <= 2) || (log10 < prefix))
                {
                    return(result);
                }

                result = Math.Pow(10, -prefix) * value;
                scale  = prefix;
            }

            return(result);
        }