예제 #1
0
            /// <summary>
            /// Applied before GetFormattedSimple runs.
            /// </summary>
            internal static bool Prefix(float num, TimeSlice timeSlice, string formatString,
                                        ref string __result)
            {
                var text = CACHED_BUILDER;

                text.Clear();
                num = GameUtil.ApplyTimeSlice(num, timeSlice);
                if (!text.AppendIfInfinite(num))
                {
                    if (formatString != null)
                    {
                        AppendSimpleFormat(text, formatString, num);
                    }
                    else if (num == 0.0f)
                    {
                        text.Append('0');
                    }
                    else
                    {
                        RyuFormat.ToString(text, (double)num, 2, RyuFormatOptions.FixedMode |
                                           RyuFormatOptions.SoftPrecision | RyuFormatOptions.
                                           ThousandsSeparators);
                    }
                }
                __result = text.AppendTimeSlice(timeSlice).ToString();
                return(false);
            }
예제 #2
0
        /// <summary>
        /// Converts a float to a standard string like ONI would, but with less memory used.
        /// </summary>
        /// <param name="f">The value to format.</param>
        /// <param name="result">The location where the formatted value will be stored.</param>
        public static void ToStandardString(this float f, StringBuilder result)
        {
            float absF      = Mathf.Abs(f);
            int   precision = (absF < 10f) ? 1 : 0;

            RyuFormat.ToString(result, (double)f, precision, RyuFormatOptions.FixedMode |
                               RyuFormatOptions.SoftPrecision | RyuFormatOptions.ThousandsSeparators);
        }
예제 #3
0
            /// <summary>
            /// Applied before GetFormattedInt runs.
            /// </summary>
            internal static bool Prefix(float num, TimeSlice timeSlice, ref string __result)
            {
                var text = CACHED_BUILDER;

                text.Clear();
                if (!text.AppendIfInfinite(num))
                {
                    RyuFormat.ToString(text, (double)GameUtil.ApplyTimeSlice(num, timeSlice),
                                       0, RyuFormatOptions.FixedMode | RyuFormatOptions.ThousandsSeparators);
                }
                __result = text.AppendTimeSlice(timeSlice).ToString();
                return(false);
            }
예제 #4
0
 /// <summary>
 /// Appends a formatted float to the buffer, with a no alloc fast case for all of the
 /// "Fx" and "Ex" strings.
 /// </summary>
 /// <param name="buffer">The string builder to append.</param>
 /// <param name="floatFormat">The format to use for the number.</param>
 /// <param name="num">The value to append.</param>
 /// <returns>The string builder.</returns>
 private static StringBuilder AppendSimpleFormat(this StringBuilder buffer,
                                                 string floatFormat, float num)
 {
     if (floatFormat.Length == 2)
     {
         char type      = floatFormat[0];
         int  precision = floatFormat[1] - '0';
         if (type == 'F')
         {
             num.ToRyuHardString(buffer, precision);
         }
         else if (type == 'E')
         {
             RyuFormat.ToString(buffer, (double)num, precision, RyuFormatOptions.
                                ExponentialMode);
         }
     }
     else
     {
         buffer.Append(num.ToString(floatFormat));
     }
     return(buffer);
 }
예제 #5
0
 /// <summary>
 /// Converts a float to a fixed decimal point format with up to the specified number
 /// of optional decimals.
 /// </summary>
 /// <param name="f">The value to format.</param>
 /// <param name="result">The location where the formatted value will be stored.</param>
 /// <param name="precision">The maximum number of decimal places.</param>
 public static void ToRyuSoftString(this float f, StringBuilder result, int precision)
 {
     RyuFormat.ToString(result, (double)f, precision, RyuFormatOptions.FixedMode |
                        RyuFormatOptions.SoftPrecision);
 }