|
It fits in with the general idea though - casting from a float/double to an int results in truncation and not rounding.
float f = 1.9f;
Console.WriteLine((int)f);
prints 1 and not 2.
|
|
|
|
|
Thanks Senthil!
From discussion with you, I found it is always truncated when convert from Decimal to other type?
Truncate means, 100.9 will result in 100.
Rounding means 100.9 will result in 101.
When rounding will happen? Previously I thought rounding will happen when do conversion, but from dicussion with you, when doing conversion, truncate other than rounding will be performned.
So, when there will be rounding?
regards,
George
|
|
|
|
|
George_George wrote: So, when there will be rounding?
When you call Math.Round[^].
|
|
|
|
|
Thanks Senthil,
So, could I make such a conclusion?
When conversion, always truncate? If yes, I am not 100% agree. A sample is, float a = 2F / 3F, when there is rounding 0.6666667, not truncating 0.6666666.
regards,
George
|
|
|
|
|
George_George wrote: If yes, I am not 100% agree. A sample is, float a = 2F / 3F, when there is rounding 0.6666667, not truncating 0.6666666
While there is no conversion involved in your expression, floating point arithmetic is a bit different. Take a look at http://www.codeproject.com/KB/dotnet/ExtremeFloatingPoint1.aspx[^]
|
|
|
|
|
Thanks Senthil!
In my sample 2F/3F, if it is not called as conversion, what is the correct terminology to call it?
regards,
George
|
|
|
|
|
I don't know the right word - the result of your expression exceeds the precision of a single precision floating point number. It's not overflow, as the range of float is much bigger.
|
|
|
|
|
Thanks Senthil,
In the article you referred, seems it is not mentioned the terminology for my sample, right?
regards,
George
|
|
|
|
|
Hi,
i am trying for WhiteBoard by connecting to remote machines using IP Address. I got source code for that. but when i run the code, i am unable to connect to the other machines... its giving error like "No connection could be made because the target machine actively refused it"
But the target machine dint receive any request to refuse... i am using the same Ip Address and port no which i have used for Audio & Video conference. There its working fine...
Below is the link for the source code...
http://www.codeproject.com/KB/dotnet/csharpwhiteboard.aspx?fid=4351&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=627213&fr=26[^]
Any help is appreciated....
Thanks in advance....
|
|
|
|
|
Firewall ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
you mean to say have i given any security?
|
|
|
|
|
I'm using Visual C#.Net 2005
I'm getting an error when I try to access a memeber variable in aother class. It's showing "Object reference not set to an instance of an object."
This is my code :
public class CCommand
{
public Byte[] byArray;
public bool fnCommand()
{
byArray= new Byte[15];
byArray= { 40, 1, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10 };
}
~CCommand()
{
}
}
I'm accessing byArray in another class like this in a function
public void fnSend()
{
CCommand clsCommand = new CCommand();
Byte nB;
for (int i = 0; i < 15; ++i)
{
clsCommand.byArrData[i] = new Byte();
nB = clsCommand.byArrData[i];
}
}
Its showing error in this line
clsCommand.byArrData[i];
what is the problem?
Thanks in advance
|
|
|
|
|
Susanmat wrote: clsCommand.byArrData
is null, I guess.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
it's b'coz u just declare the array in the class but initialize it in the fnCommand function.
u shud call that function first and then use the array object.
e.g.
CCommand clsCommand = new CCommand();
clsCommand.fnCommand();
cls.byArrData[i]...
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
Susanmat wrote: Its showing error in this line
clsCommand.byArrData[i];
what is the problem?
The name of the member is byArray , not byArrData .
If that's not the actual problem, you should show the actual code that you are using instead of some code that you are not using. It's hard to find an error in your code by looking at something that is not.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi,
Can anybody help me out how to use http protocol as a transportation in socket programming.
|
|
|
|
|
Hi All,
I have a text file having german text. The Text contains some special characters like 'ß','Ä','Ü' etc. i want to convert the text using codepage 850. But after conversion it is showing garbage for above characters.This might happen because these characters are incorrectly translated due to incorrect coding of translation table for code page 850. What should i do to display these characters properly after conversion?
I am using following code for doing that
//Create a new stream for the input file
StreamReader stream = null;
stream = new StreamReader(@"D:\SampleGermanText.txt", Encoding.GetEncoding(850), true);
string strLine = stream.ReadLine();
while (stream.EndOfStream == false) //loop until end of the file.
{
LogMessage(strLine);
strLine = stream.ReadLine();
}
stream.Close();
Thanks,
Tushar
|
|
|
|
|
Either your input is wrong (maybe the file isn't using codepage 850, but Windows-1252?), or your output is wrong. What does the LogMessage function do to output the string?
|
|
|
|
|
Hi,
I have a COM object that is build for x64 platform. I wanted to debug this COM object with my C# TestDriver program (also used x64 platform).
When I enable "Enabled unmanaged code debugging", the application won't start. I gave me this error:
Error while trying to run project: Unable to start program 'C:\Temp\COM\TestDriver\TestDriver.exe'.
The debugger does not support debugging managed and native code at the same time on this platform.
Everything works fine for x86 platform (of course, my COM object also build for x86 platform).
Any idea?
Cheers
|
|
|
|
|
Hi All,
I created one personal folder in outlook.Now i wanna access that personal folder calendar events from c# program.i tried this but it directly access the default calender.i want to access which i created in outlook personal folder calendar.Give me any commends regarding this.
Thanx Much in Advance...
Mohan.T
Mohan t working for N.I.C
|
|
|
|
|
I am in a bit of a pickle. I need to write a windows application using Visual Studio 2005, I have an Accpac Financial System that has an API named XAPI.
What I did was that I will add this API as a reference and then insert the using namespace for the API, I have also added the namespace System.Runtime.InteropServices as this API works with an old COM component.
Now if I retrieve a value from the DB in the button_click event everything works. If I copy that code and put it in a method, say "public object Test()" and then reference the Test() in the button_click everything works.
Now I take that same code and copy that into a Class Library. I replace all the textboxes with property values as the textboxes cannot be accessed in the library. If I run the application I get a "Error HRESULT E_FAIL has been returned from a call to a COM component."
Can someone please help me with this?? I think it has something to do with the properties but I am not sure...
Thanks in advance!!
Illegal Operation
|
|
|
|
|
Are you accessing the class library from a console application? IIRC, console projects don't have the [STAThread] attribute set for Main, while WinForms projects do. Can you check whether the code accessing your library has [STAThread] set for its Main method?
|
|
|
|
|
I checked in the Program.cs and the [STAThread] has been set. It is a windows application that needs to execute methods from an external dll...
Illegal Operation
|
|
|
|
|
Hello everyone,
Sorry for this stupid question, as I am migrated from C++ to C#. In C++ there is no concept of property, except in COM.
For static property of a class in C# (e.g. DateTime.Now), I think there is nothing special compared to a non-static property, except we need to access the property by class name other than by instance variable name?
In my usage of static property, I feel no special point compared with static function. Correct?
thanks in advance,
George
|
|
|
|
|
You know properties are getter and setters and compiled into normal methods. Say you have property named "MyProperty" which will be compiled into get_MyProperty() and set_MyProperty() .
Non-static members are instance members which requires an instance for accessing. Statics are class members and can be accessed directly.
|
|
|
|