|
Hence my second paragraph about being spoilt working on server systems with gargantuan amounts of memory.
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
Hi
I have a decimal value which i want to convert to string but it drops off .0 (decimal)
I can't format since whatever value in decimal I want it as it is in string
ex. 88.99 88.00 88.0 or just 88
Thanks
Thanks
|
|
|
|
|
double val = 88.00;
string valStringWithZeroes = string.Format("{0:0.00}", val);
You can see a list of string formatting options from this blog posting[^].
|
|
|
|
|
This is great but doesn't work if i have 88.0 it will format that to 88.00
I want which shows # as it is ... like 88.0 or 88888.888
Thanks
|
|
|
|
|
Your problem is that
double val = 88.0;
Is the same value as
double val = 88.0000;
They're the same in the real mathematical sense of decimal values, as well as the same in the CLR. So, there's no way for you to print out whether it's 88.0 or 88.0000 if you're storing it as a double. I'm not sure whether there's a type in the CLR that stores an arbitrary number of decimal places as part of the value type itself.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
Judah Himango wrote: They're the same in the real mathematical sense of decimal values, as well as the same in the CLR. So, there's no way for you to print out whether it's 88.0 or 88.0000 if you're storing it as a double. I'm not sure whether there's a type in the CLR that stores an arbitrary number of decimal places as part of the value type itself.
For something not being modifed in code, String.
If you need to use it arithmatically, I'd suggest looking at scientific libraries for a class that handles significant figures, because with SF 88.1 != 88.10. The former represents the range 88.05
|
|
|
|
|
dan neely wrote: SF 88.1 != 88.10
I knew someone would call me out on this. It all depends on the context really; if we're talking about precision, yes, they are obviously not the same. If we're talking about simple arithmetic, they are the same value if precision is ignored (which is often the case in arithmetic). Anyways...for his uses, he'll need to either get a scientific library or write a type that preserves decimal precision, so it seems. I can't find any type in the CLR that preserves decimal precision.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
I know 88 is same as 88.0 or 88.00 but according to my requriments i have two #'s coming in ex 00.00 as string aand 88.00 as decimal .... now i have to compare string # to decimal which means that my number should have 2 digit before decimal and 2 digit after
another example one # is 0.0 measn another # should have one digit before decimal and one digit after decimal ... regardless of 8.0 is same as 8.00 or 8 ... in my case only 8.0 or 8.1 0r 8.2 or 9.1 are the valid digit since one digit after decimal and one digit before decimal
That's why i can't use formating since i don't what's the 1st # will look like which is string and what's the 2nd # looks like which is decimal
Thanks
|
|
|
|
|
Judah Himango wrote: dan neely wrote:
SF 88.1 != 88.10
I knew someone would call me out on this. It all depends on the context really; if we're talking about precision, yes, they are obviously not the same.
true. I mainly included it since I wasn't sure what the OP wanted, and wanted to epxlain why the class was doing what it was and check for potential side effects instead of assuming it was a 'double but keeps empty decimal places' and then getting burned over it enforcing SF, or the like.
|
|
|
|
|
The problem is that there is no single format that will achieve your goal
Say you have 88.0 and 88888.888
Console.WriteLine("{0 ##}", num)
will give you
88.0
88888.888
the problem is that if you have another number of finer precision, say 99.1234, it will be rounded to 99.124.
If you use the general format g
Console.WriteLine("{0:g}", num)
then you will get
88
88888.888
99.1234
If you have a hard need to display 88 as 88.0 then you will probably need to use two format strings
Dim nums() As Double = {88, 88888.888}
Dim numFmt As String
For Each num As Double In nums
Dim tmpNum As Double = System.Math.Abs(num)
If (System.Math.Floor(tmpNum) = tmpNum) Then
numFmt = "#.0"
Else
numFmt = "g"
End If
Dim exprFmt As String = "{0:" & numFmt & "}"
Console.WriteLine(exprFmt)
Console.WriteLine(String.Format(exprFmt, num))
Next
End Sub
NOTE: When testing this, it works well for Doubles but not singles. Don't know why
hth,
Alan.
if (
|
|
|
|
|
Well! Dears.
i have an mdi form in which i open differnet child forms . when both parent and child are maximized its ok but when i restore the MDI parent form it disturbs the layout of Child form that was Maximized in MDI. What i want is that when i restore MDI form it doesnt disturb the layout design of Child form instead it (MDI form) gets Horizantal and vertical scroll bar keeping the Child Form Maximized and undisturbed. How to do that.
Thnx in Advance.
|
|
|
|
|
If you're asking how to automatically get scrollbars to some control, look at System.Windows.Forms.ScrollableControl. When some control added to a ScrollableControl extends beyond the visible portion of the ScrollableControl, scrollbars will automatically appear.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
hi !
I want to save the value of date with the using DateTimePicker Control in a sql table with the date Format .
...<br />
try{<br />
strSQL ="update mytable set name='"+txtName.Text+ "',mydate='"+DateTimePicker1.???? ......
Any guid is very appereciated.
Regards
s_mostafa_h
-- modified at 9:30 Wednesday 22nd February, 2006
|
|
|
|
|
string commandText = "UPDATE mytable SET name = @name, mydate = @date";
SqlCommand command = new SqlCommand(commandText, myConnection);
command.Parameters.Add(new SqlParameter("@name", txtName.Text));
command.Parameters.Add(new SqlParameter("@date", dateTimePicker1.Value));
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
I Wrote this :
try{<br />
strSQL ="update mytable set name='"+txtName.Text+ "',mydate='"+DateTimePicker1.Value+"'";<br />
cnSQL = new SqlConnection(Connectionstring);<br />
cnSQL.Open();<br />
cmSQL = new SqlCommand(strSQL, cnSQL);<br />
cmSQL.ExecuteNonQuery();<br />
cnSQL.Close();<br />
cmSQL.Dispose();<br />
cnSQL.Dispose();<br />
} <br />
catch(SqlException e)<br />
{<br />
MessageBox.Show(e.Message, "Error");<br />
} But I have this Error :
syntax error converting datetime from character string
the type of mydate field is datetime .
please guide me !
thanks
s_mostafa_h
|
|
|
|
|
mostafa_h wrote: strSQL ="update mytable set name='"+txtName.Text+ "',mydate='"+DateTimePicker1.Value+"'";
Don't do that. You're opening yourself up to SQL injection attacks[^]. I showed you the proper way to do it in my last reply (by using SqlParameter objects). If you follow that course of action, you won't get the error.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
thanks of your guide !
REGARDS ,
s_mostafa_h
|
|
|
|
|
mostafa_h wrote: Any guid is very appereciated
{DB618332-94FC-4171-BFCC-BA654F5EED58}
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Michel Prévost wrote: {DB618332-94FC-4171-BFCC-BA654F5EED58}
{DB618332-94FC-4171-BFCC-BA654F5EED58}
Any guide is very appreciated .
excuse me for my poor english .
s_mostafa_h
|
|
|
|
|
No problem, english is not my first language either. I just hope you are not angry at me, I couldn't resist doing the joke.
I guess you know what a GUID is...
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
-- modified at 13:26 Wednesday 22nd February, 2006
|
|
|
|
|
ofcourse , there are a lot of expression that i don't know the meaning it .
in any case , I'm always . Now it's 01:44:50 o'clock (midnight).
s_mostafa_h
|
|
|
|
|
Hi evry body
How I can Use Thread In my program to run a Methode Continual with a littel Sleep.?
Do Methode needs to delegate for using in Threading?
---------------------
Areff Bahrami(KAVEH)
Areff.HB@Gmail.com
---------------------
|
|
|
|
|
|
Areff,
If its a windows app use the backgroundWorker control, alternatively :
Using System.Threading;
Thread myThread = new Thread(new ThreadStart(myMethod));
Thread.Sleep(1000); //Sleep for 1 second
HTH
Jonny
|
|
|
|
|
Areff,
If its a windows app use the backgroundWorker control, alternatively heres a code snippet :
--
Using System.Threading;
Thread myThread = new Thread(new ThreadStart(myMethod));
Thread.Sleep(1000); //Sleep for 1 second
--
HTH
Jonny
Jonny
|
|
|
|