23 using System.Globalization;
25 namespace Lucene.Net.Support
39 public static System.Single Parse(System.String s, System.Globalization.NumberStyles style, System.IFormatProvider provider)
41 if (s.EndsWith(
"f") || s.EndsWith(
"F"))
42 return System.Single.
Parse(s.Substring(0, s.Length - 1), style, provider);
44 return System.Single.
Parse(s, style, provider);
53 public static System.Single Parse(System.String s, System.IFormatProvider provider)
55 if (s.EndsWith(
"f") || s.EndsWith(
"F"))
56 return System.Single.
Parse(s.Substring(0, s.Length - 1), provider);
58 return System.Single.
Parse(s, provider);
67 public static System.Single Parse(System.String s, System.Globalization.NumberStyles style)
69 if (s.EndsWith(
"f") || s.EndsWith(
"F"))
70 return System.Single.
Parse(s.Substring(0, s.Length - 1), style);
72 return System.Single.
Parse(s, style);
80 public static System.Single Parse(System.String s)
82 if (s.EndsWith(
"f") || s.EndsWith(
"F"))
83 return System.Single.
Parse(s.Substring(0, s.Length - 1).Replace(
".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
85 return System.Single.
Parse(s.Replace(
".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
88 public static bool TryParse(System.String s, out
float f)
92 if (s.EndsWith(
"f") || s.EndsWith(
"F"))
93 ok = System.Single.
TryParse(s.Substring(0, s.Length - 1).Replace(
".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator), out f);
95 ok = System.Single.TryParse(s.Replace(
".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator), out f);
105 public static string ToString(
float f)
107 return f.ToString().Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator,
".");
116 public static string ToString(
float f,
string format)
118 return f.ToString(format).Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator,
".");
121 public static int FloatToIntBits(
float value)
123 return BitConverter.ToInt32(BitConverter.GetBytes(value), 0);
126 public static float IntBitsToFloat(
int value)
128 return BitConverter.ToSingle(BitConverter.GetBytes(value), 0);