[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private/NumberFormat G
From: |
Jonathan Springer <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private/NumberFormat GeneralFormatter.cs,1.3,1.4 ScientificFormatter.cs,1.3,1.4 |
Date: |
Thu, 16 Jan 2003 20:08:48 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat
In directory subversions:/tmp/cvs-serv31032/runtime/System/Private/NumberFormat
Modified Files:
GeneralFormatter.cs ScientificFormatter.cs
Log Message:
Floating point Parse/ToString fixes.
Index: GeneralFormatter.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/GeneralFormatter.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** GeneralFormatter.cs 29 Nov 2002 00:58:38 -0000 1.3
--- GeneralFormatter.cs 17 Jan 2003 01:08:46 -0000 1.4
***************
*** 60,63 ****
--- 60,81 ----
}
+ private string StripTrail(string s, IFormatProvider provider)
+ {
+ StringBuilder sb = new StringBuilder(s);
+ String ds = NumberFormatInfo(provider).NumberDecimalSeparator;
+
+ // Strip unnecessary trailing zeroes and point
+ if (sb.ToString().IndexOf(ds) >= 0)
+ {
+ while (sb[sb.Length - 1] == '0')
sb.Remove(sb.Length-1,1);
+ if (sb.ToString().IndexOf(ds) == sb.Length - ds.Length)
+ {
+ sb.Remove(sb.Length-ds.Length, ds.Length);
+ }
+ }
+
+ return sb.ToString();
+ }
+
public override string Format(Object o, IFormatProvider provider)
{
***************
*** 73,77 ****
}
! exponent = (int) Math.Floor(Math.Log10(OToDouble(o)));
if (IsSignedInt(o) || IsUnsignedInt(o))
--- 91,102 ----
}
! if (OToDouble(o) == 0.0d)
! {
! exponent = 0;
! }
! else
! {
! exponent = (int) Math.Floor(Math.Log10(OToDouble(o)));
! }
if (IsSignedInt(o) || IsUnsignedInt(o))
***************
*** 79,83 ****
if (exponent < precision)
{
! return new FixedPointFormatter(0).Format(o,
provider);
}
else
--- 104,111 ----
if (exponent < precision)
{
! return StripTrail(
! new
FixedPointFormatter(0).Format(o, provider),
! provider);
!
}
else
***************
*** 90,94 ****
if (exponent >= -4 && exponent < precision)
{
! return new FixedPointFormatter(precision).Format(o,
provider);
}
else
--- 118,124 ----
if (exponent >= -4 && exponent < precision)
{
! return StripTrail(
! new
FixedPointFormatter(precision).Format(o, provider),
! provider);
}
else
Index: ScientificFormatter.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/ScientificFormatter.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** ScientificFormatter.cs 1 Jan 2003 18:12:58 -0000 1.3
--- ScientificFormatter.cs 17 Jan 2003 01:08:46 -0000 1.4
***************
*** 59,66 ****
// Calculate exponent and mantissa
! exponent = (int) Math.Floor(Math.Log10(value));
! mantissa = value / Math.Pow(10, exponent);
rawnumber = FormatFloat(mantissa, precision);
ret = new StringBuilder(
--- 59,75 ----
// Calculate exponent and mantissa
! if (value == 0.0d)
! {
! exponent = 0;
! mantissa = 0.0d;
! }
! else
! {
! exponent = (int) Math.Floor(Math.Log10(value));
! mantissa = value / Math.Pow(10, exponent);
! }
rawnumber = FormatFloat(mantissa, precision);
+ if (rawnumber.Length == 0) rawnumber = "0";
ret = new StringBuilder(
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private/NumberFormat GeneralFormatter.cs,1.3,1.4 ScientificFormatter.cs,1.3,1.4,
Jonathan Springer <address@hidden> <=