TheSwamp
Code Red => .NET => Topic started by: T.Willey on September 19, 2008, 03:47:45 PM
-
I never knew that you could tell it how many decimal places you wanted it to show. I have used 'ToString', but always typed it so fast that I didn't see you could format it. So I was thinking that I was going to have to write a format function for some reals, so that they will show all the decimals I want. So incase you haven't used the format options on 'ToString', it goes like
real = 7.00
real.ToString() = "7"
real.ToString( "0.00" ) = "7.00"
real = 7.05
real.ToString() = "7.05"
real.ToString( "0.0" ) = "7.1"
Man I can't believe I missed that, but I don't think I ever had a use for it until now.
It must be Friday.....
-
Friday...definately ;) (you used that one on me last Friday I believe in another thread).
Wait 'till you start getting into custom format specifiers.... :evil:
-
Friday...definately ;) (you used that one on me last Friday I believe in another thread).
Yea, I love the Friday excuse.
Wait 'till you start getting into custom format specifiers.... :evil:
I looked at those before I knew I could format it with just the ToString call, but didn't feel like reading/understanding it today.
-
I never knew that you could tell it how many decimal places you wanted it to show. I have used 'ToString', but always typed it so fast that I didn't see you could format it. So I was thinking that I was going to have to write a format function for some reals, so that they will show all the decimals I want. So incase you haven't used the format options on 'ToString', it goes like
real = 7.00
real.ToString() = "7"
real.ToString( "0.00" ) = "7.00"
real = 7.05
real.ToString() = "7.05"
real.ToString( "0.0" ) = "7.1"
Man I can't believe I missed that, but I don't think I ever had a use for it until now.
It must be Friday.....
And you don't have to wait for the other next Friday, to know that you can use :)
Autodesk.AutoCAD.Runtime.DistanceToString(double, DistanceUnitFormat, int); // distance to format // Lunits // Precision
Example:
str_distanceCorner = editDistanceCorner.Text;
double d_distCorner = Converter.StringToDistance(str_distanceCorner, DistanceUnitFormat.Architectural);
editDistanceCorner.Text = Converter.DistanceToString(d_distCorner, DistanceUnitFormat.Architectural, -1); // where -1 is current Luprec value
-
Since the topic has come up, is there an easy way to specify the maximum digits after the decimal? For example, if I set it to 2 decimal places, I would see the following:
value = display
1 = 1
1.5 = 1.5
1.52 = 1.52
1.5555 = 1.56
1.50 = 1.5
1.00 = 1
I wrote a little routine that strips the trailing zeros (and decimal point, if applicable) from the end of the input value, which was simple enough, but I was wondering if there was some built-in way to do this.
-
Tim's example does that
double d = 121.500001;
ed.WriteMessage("\n" + d.ToString("0.00"));
121.50
-
well I didn't read your post well sinc but I think this is what you want
the 0.00 will leave the zeroes whereas 0.## wont.
double[]dNums=new double[] { 1,1.5, 1.52,1.5555,1.50,1.00 };
foreach (double d in dNums)
{
ed.WriteMessage("\nFormat 0.00=" + d.ToString("0.00"));
ed.WriteMessage("\nFormat 0.##=" + d.ToString("0.##"));
}
Format 0.00=1.00
Format 0.##=1
Format 0.00=1.50
Format 0.##=1.5
Format 0.00=1.52
Format 0.##=1.52
Format 0.00=1.56
Format 0.##=1.56
Format 0.00=1.50
Format 0.##=1.5
Format 0.00=1.00
Format 0.##=1
-
Yeah, that's it. Thanks!
-
Thanks Luis. Didn't even look in the Acad stuff. I like. Too bad I can't go home already since I did learn something new already.
Nice solution Bryco. I wouldn't have even thought of doing it that way.