lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "George Aroush" <geo...@aroush.net>
Subject RE: Converting float values to string
Date Sat, 17 Jun 2006 11:51:49 GMT
Hi folks,

This is the solution that I came up with:

	public static System.String Boost(float boost)
	{
		if (boost != 1.0f)
		{
			float boostAsLong = (long) boost;
			if (boostAsLong == boost)
				return "^" + boost.ToString(".0");
			return "^" + boost.ToString();
		}
		else
			return "";
	}

Let me know if you have a better way to this.

Regards,

-- George 

-----Original Message-----
From: George Aroush [mailto:george@aroush.net] 
Sent: Friday, June 16, 2006 4:27 PM
To: lucene-net-dev@incubator.apache.org
Subject: Converting float values to string

Hi folks,

Some NUnit tests are failing because Lucene.Net.Util.ToStringUtils.Boost()
is not return the correct formatted float value as it would be in the Java
version.

For example, given he float value of 2, in Java you will get back the string
"2.0" -- but in C# it is giving back "2".  Here is the function in question:

	public static System.String Boost(float boost)
	{
		if (boost != 1.0f)
		{
			return "^" + boost.ToString();
		}
		else
			return "";
	}

If I change "boost.ToString()" to "boost.ToString("0.0")" it will work on
float values such as 1, 12.1, 9999.5, etc., where I get back "1.0", "12.1",
"9999.5", etc. -- however, this won't work for float values of 1.005, or
1.01.  In those cases, I get back "1.0".

Do you know how I can make this code work in .NET so that I get back "1.005"
and "1.01" -- as the Java version is doing it?

Regards,

-- George


Mime
View raw message