/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Lucene.Net.Support
{
///
///
///
public class Single
{
///
///
///
///
///
///
///
public static System.Single Parse(System.String s, System.Globalization.NumberStyles style, System.IFormatProvider provider)
{
try
{
if (s.EndsWith("f") || s.EndsWith("F"))
return System.Single.Parse(s.Substring(0, s.Length - 1), style, provider);
else
return System.Single.Parse(s, style, provider);
}
catch (System.FormatException fex)
{
throw fex;
}
}
///
///
///
///
///
///
public static System.Single Parse(System.String s, System.IFormatProvider provider)
{
try
{
if (s.EndsWith("f") || s.EndsWith("F"))
return System.Single.Parse(s.Substring(0, s.Length - 1), provider);
else
return System.Single.Parse(s, provider);
}
catch (System.FormatException fex)
{
throw fex;
}
}
///
///
///
///
///
///
public static System.Single Parse(System.String s, System.Globalization.NumberStyles style)
{
try
{
if (s.EndsWith("f") || s.EndsWith("F"))
return System.Single.Parse(s.Substring(0, s.Length - 1), style);
else
return System.Single.Parse(s, style);
}
catch(System.FormatException fex)
{
throw fex;
}
}
///
///
///
///
///
public static System.Single Parse(System.String s)
{
try
{
if (s.EndsWith("f") || s.EndsWith("F"))
return System.Single.Parse(s.Substring(0, s.Length - 1).Replace(".", System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
else
return System.Single.Parse(s.Replace(".", System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
}
catch(System.FormatException fex)
{
throw fex;
}
}
public static bool TryParse(System.String s, out float f)
{
bool ok = false;
if (s.EndsWith("f") || s.EndsWith("F"))
ok = System.Single.TryParse(s.Substring(0, s.Length - 1).Replace(".", System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator), out f);
else
ok = System.Single.TryParse(s.Replace(".", System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator), out f);
return ok;
}
///
///
///
///
///
public static string ToString(float f)
{
return f.ToString().Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, ".");
}
///
///
///
///
///
///
public static string ToString(float f, string format)
{
return f.ToString(format).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, ".");
}
}
}