|
|
I have following:
string dec = "2";
string amount = "1000"
I want to put a decimal in 1000 based on dec number. So for instance if dec=3 >>> amount should become 10.000....if dec = 2, amount=100.00
How can I achieve this type of operation??
regards
|
|
|
|
|
how about something like this:
<br />
int iDec = int.Parse(dec)<br />
double dAmount = double.Parse(amount)<br />
dAmount *= 10;
dAmount /= Math.Pow(10,iDec);<br />
Amount = dAmount.ToString("f" + iDec);<br />
<code>
|
|
|
|
|
or
amount.Substring(0,amount.Length-(dec[0]-'0'))+"."+amount.SubString(amount.Length-(dec[0]-'0')
xacc-ide 0.0.99-preview7 now with C#, C, C++, IL, XML, Nemerle, IronPython, Perl, Caml, SML, Ruby, Flex, Yacc, Java, Javascript, Lua, Prolog and Boo highlighting support!
|
|
|
|
|
this worked for me. thanks
|
|
|
|
|
Is there any equivalent of the _MFC_VER macro for the C# preprocessor that allows the user to detect the CLR version at compile time? I saw something like _CLR_VER in the 2005 C++ docs, but nothing for VB.net, C# or C++ for the .NET 1.0, 1.1 versions. ( I am using C# 2003 latest service packs.)
.............................
There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life.
Fiat justitia, et ruat cælum
|
|
|
|
|
No, there isn't.
If you using C# 2003, you'll be compiling using the .NET Framework 1.1. VS.NET 2003 will NOT compile using 1.0 or 2.0 of the .NET Framework.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
There isn't. Java and .Net have been gravitating away from the concept of a "pre-compile" step so there is no "preprocessor" to mess with. I believe ultimately this is a good thing since it leads to cleaner, far more readible code.
More to the point, why do you need to know, at compile time, what version of the CLR is available? You need to remember that a machine might have multiple versions (if not multiple implementations) of CLR available to run against. What would one do with such information in any C# code anyway? Versioning is handled by attributes and metadata where the compiler doesn't care (beyond generating correct IL).
|
|
|
|
|
I was concerned with the availability of obsolete functions or methods from one version of the CLR to another. With a CLR version compile time symbol definition I hoped to avoid all those obsolete methods messages.
I will have to perform run-time detection of the CLR, but was hoping to use a ConditionalAttribute with the CLR version for source I might distribute that would work on 1.1 or 2.0 of the CLR.
Oh well.
.............................
There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life.
Fiat justitia, et ruat cælum
|
|
|
|
|
hi to all,
in a listview how can align right only the data in the column without the title of the same column.
in other word :
the title must be align to the left and the data must be align to the right
best regards and thanks in advance
fady
|
|
|
|
|
I'm learning C# and am using VS.net 2003 with SQL server 2005. I have a table called Train_Schedule with a filed of type smalldatetime called Arrival_Time .
I created a typed dataset called Train (similar in structure to Train_Schedule ) and bound it to my datagrid, stationGrid . In my form, I have a datetimepicker called arrivalTimePicker , which displays the time in a custom format of hh : mm tt . The MaxDate and MinDate properties are set to the current date, so the user can only select the time.
In a button click's event handler, I have the following code:
string arrivalTime = arrivalTimePicker.Value.ToShortTimeString();
MessageBox.Show(arrivalTime);
object[] rowData = new object[5];
rowData[0] = trainNumber;
rowData[1] = stopNumber;
rowData[2] = stationCode;
rowData[3] = arrivalTime;
rowData[4] = departureTime;
DataSet trainDataSource = (DataSet) stationGrid.DataSource;
trainDataSource.Tables[0].Rows.Add(rowData);
But the grid displays only the date, not the time. How can I display the time and not the date in the datagrid?
Thanks in advance!
Cheers,
Vikram.
Google talk: binarybandit upsdude: when I looked at laurens profile, a couple of gears got stripped in my brain.
Michael Martin: Too bad she bats for the other team.
|
|
|
|
|
Have you tried -
string arrivalTime = arrivalTimePicker.Value.ToString("hh:mm:ss");
|
|
|
|
|
I have some code that builds a web form datagrid on the fly. This method ...
{
bc = new BoundColumn();
.
.
.
if( c.ItemType == "Time" )
{
bc.DataFormatString = "{0:t}";
bc.ItemStyle.Wrap = false;
}
if( c.ItemType == "Date" )
{
bc.DataFormatString = "{0:d}";
bc.ItemStyle.Wrap = false;
}
DataGrid1.Columns.Add( bc );
}
... seems to work for me.
-- modified at 8:51 Tuesday 18th October, 2005
|
|
|
|
|
Stan, I'm using a Windows forms application. I don't generate columns on the fly; rather, I use a typed dataset.
DataFormatString is not a property of System.Data.DataColumn .
Any workarounds?
Woah! Managed to post this after 1+ hour of trying!
Cheers,
Vikram.
http://www.geocities.com/vpunathambekar
Google talk: binarybandit After all is said and done, much is said and little is done.
|
|
|
|
|
|
Hi,
Is there anyway of differentiating whether a controls Leave event was fired by a "TAB" out of the control or by a "Mouse Move" out of the control. I am trying to pop-up a window whent he user "tabs" out of a control which is fine but it is also happening when they "mouse move" out of the control. I am using the controls Leave event. Any help will be greatly appreciated.
Thanx
Craigo
|
|
|
|
|
I would imagine (although I haven't tried this) you could intecept both the MouseMove and the KeyDown events for your control then in the KeyDown event check for the tab key and if it was pressed set a flag, lets call it TabPressed, to true (else false). In the MouseMove event you would set TabPressed to false. When your control Leave event fires you can then check if TabPressed is true and pop-up your window if it is, else don't.
|
|
|
|
|
Thanx for the reply....the problem is that you cannot trap the Tab key on the KeyDown event becase when you press the tab key it doesnt fire the keydown event, only the OnLeave event fires.
|
|
|
|
|
Hmmm....what if you set the KeyPreview property of the form that contains your control to true and handle the KeyDown event there? Will that let you see the KeyDown before the OnLeave event?
-- modified at 9:47 Tuesday 18th October, 2005
Actually, another thought. Perhaps you could check the mouse position using Cursor.Position in your OnLeave event and check to see if it is within your control or not?
Or better yet (maybe) perhaps you need to handle the MouseEnter and MouseLeave events for your control. Keep a flag (set on the MouseEnter and MouseLeave events) of whether the mouse is within the control. When the control first gets focus store the current state of that flag. On your OnLeave event check to see if the current flag state indicates that the mouse is outside the control where before it was inside. There are some details there that you'd have to work out, but it's something to think about.
|
|
|
|
|
iam doing a project on cryptology in c# i need help in the topic
like what i can are features that i can include and what are the new features in
cryptology please help me out...
MADE BY SANDY
BAD COMPANY
|
|
|
|
|
|
hi thanks for ur help actually my real name is sandeep francis
MADE BY SANDY
BAD COMPANY
|
|
|
|
|
Erm, there's lots of stuff in System.Security.Cryptography[^]. It's unlikely you will learn much about it by adding "using System.Security.Cryptography" to a .cs file though.
Ryan
O fools, awake! The rites you sacred hold
Are but a cheat contrived by men of old,
Who lusted after wealth and gained their lust
And died in baseness—and their law is dust.
al-Ma'arri (973-1057)
|
|
|
|
|
i am try to write tcp client an server but any time it get to the streamReader it hungs.
can someone help me with these code
Client Code
public string RunClient(string address,int port)
{
string response="";
//set up a listener on that address/port
TcpClient tcpClient=new TcpClient(address,port);
if(tcpClient!=null)
{
string message="Hello There";
//translate the message into UTFASCII and store it as a byte array
byte[] bytes=Encoding.ASCII.GetBytes(message);
NetworkStream stream=tcpClient.GetStream();
//send message to the connected tcpServer
//the write flushes the stream automatically here
stream.Write(bytes,0,bytes.Length);
//get the response from the server
StreamReader reader=new StreamReader(stream,Encoding.UTF8);
try
{
response=reader.ReadToEnd();
}
finally
{
//close reader
reader.Close();
}
//close client
tcpClient.Close();
}
//return response to text
return response;
}
Server Code
public static void RunServer(string address,int port)
{
//set up address
IPAddress addr=IPAddress.Parse(address);
//set up listener on that address/port
TcpListener tcpListener=new TcpListener(addr,port);
if(tcpListener !=null)
{
//start it up
tcpListener.Start();
//wait for tcp client to connect
TcpClient tcpClient=tcpListener.AcceptTcpClient();
byte[]bytes=new byte[1024];
//get the client stream
NetworkStream ClientStream=tcpClient.GetStream();
Stream str=ClientStream;
StreamReader reader=new StreamReader(ClientStream,Encoding.UTF8);
try
{
string request=reader.ReadToEnd();
//just send an acknowlegment
bytes=Encoding.UTF8.GetBytes("Thanks for the message");
ClientStream.Write(bytes,0,bytes.Length);
}
finally
{
//close the resder
reader.Close();
}
//stop listeneing
tcpListener.Stop();
}
}
|
|
|
|
|