|
Hello could any body help me, i need to record the live stream coming from ip devices into a video file. I have looked online for various sdks, but not much luck, i need to do this in c#. Any help would be apriciated. Many thanks
|
|
|
|
|
Hi people
I have a TextBlock that displays a calculated cost. The cost is stored in a double, and then I set TextBlock.Text to the cost.ToString(). What I want to know is, how do I convert this double value so that it displays only 2 decimal points e.g 56.99. Because at the moment it displays something like the following: 56.9999999999.
|
|
|
|
|
cost.ToString("N2");
have a look at this[^]
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
string ss = cost.ToString("N");
Have fun.
var question = (_2b || !(_2b));
|
|
|
|
|
Etienne_123 wrote: displays only 2 decimal points e.g 56.99.
you probably mean two fractional digits, a real number only has one decimal point.
x.ToString("F2") would work for me; how about looking at the documentation?
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Nevermind I figured it out.
I used:
double costTwoDecimals = Math.Round(costTotal, 2);
|
|
|
|
|
Etienne_123 wrote: Nevermind I figured it out.
I used:
double costTwoDecimals = Math.Round(costTotal, 2);
...That's not what you asked for. if you pass that function 56.9999999999 you will get 57 not 56.99 like you said you wanted.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
As far as I know, the framework doesn't provide this explicitly. However, if you really must return a truncated string, then I've whipped up an extension method for you:
public static string ToDecimalPlace(this double i, int decimalPlaces)
{
string toString = i.ToString();
int decimalPoint = 0;
if ((i % 1) == 0)
return toString;
decimalPoint = toString.IndexOf('.');
return toString.Substring(0, decimalPoint + decimalPlaces + 1);
}
I'm personally a little concerned about the strings being created, but I can't see a simple way around that problem. It will only usually show up under high load anyway. And remember to vet the input - this is only a proof of concept. If you do something like (8.1111111111111111111111111).ToDecimalPlace(840) you'll get an IndexOutOfRange exception.
|
|
|
|
|
Computafreak wrote: As far as I know, the framework doesn't provide this explicitly
double.ToString("F2")
|
|
|
|
|
I've seen that. But when I declare a simple double variable, with a value identical to that of the OP, then call ToString("F2") , I simply get 57.00. It seems to round instead of truncate.
|
|
|
|
|
Similar to the Computafreak solution, use an extension method:
public static double Truncate(this double d, int places)
{
double pow = Math.Pow(10, places);
return Math.Truncate(d * pow) / pow;
}
You can then use myDouble.Truncate(2).ToString() with any formatting you want.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Wow, that's clever. I hadn't thought of doing that - it'll be filed away for future use. That's actually a lot better than mine as well, because it doesn't use strings.
For the OP, what this function does is move the decimal place right by the number of places you want to get. Then it strips off the rest of the decimal places on that number, and moves the decimal place back again, so that everything stays the same. The sequence of events, assuming you want to convert 1.23456789 to 1.234 is this:
1.23456789 -> 1234.56789
Truncate -> 1234
Divide again -> 1.234
|
|
|
|
|
The benefits of age and experience! (Or, being an old fart has some advantages, then...)
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hello, I'm kind of new in C#. How i be able to access a method from my mainform from another form inside another project, but the same solution, without having to create a new object instance of the mainform?
for example, my mainform from project MainModule has a method to localize data, something like this:
public void LocalizeData(CultureInfo culture)
{
//codes here
}
How can i Access that from another project ModuleBody:
public void submit_click(Object sender, EventArgs e)
{
//How to access LocalizeData Method
}
Please help. Thanks.
|
|
|
|
|
If the code is common (ie the same in each case) create a new class with the localisation code in. You will almost certainly need to pass in the instance of the form you want to be localised.
e.g. [Psuedocode]
public class Localizer
{
Form FormInstance { get; set; }
public void LocalizeData(CultureInfo culture)
{
}
public Localizer(Form formInstance)
{
FormInstance = fromInstace;
}
}
|
|
|
|
|
I write windows service but I can't install it on windows 7.
What is the diffirentation between windows 7 and other windows OS when install windows service?
|
|
|
|
|
None, AFAIK.
What error are you getting? Are you sure you are using administrative privileges when istalling the service?
|
|
|
|
|
I don't get any error. I install windows service using with installutil but I can't see my installed service in the windows services.
I use same code on different windows OS, its work.
|
|
|
|
|
Hi,
How do I get Excel Application object in automation add-in that is passed from VSTO Excel add-in 2003?
Thanks in Advance
|
|
|
|
|
HI,
In a special case in our project i have to draw around 180,000 rectangles on the window, Its taking almost 2 seconds to do it, and it has zoom and scrolling features too. Is there any way to impove the performance.
Thanks
ravi
|
|
|
|
|
|
double-buffering improves the visual experience, it does not really change the execution speed.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Thanks, I know that.
The OP was talking about zoom and scrolling features. I decided that double-buffering technique could greatly improve the visual experience when using these features.
Thanks
Nuri Ismail
|
|
|
|
|
That is a lot of rectangles, are you by any chance using them to represent a grid? If so then you could try using lines to draw the grid, this would reduce the number of draws to ~900. If not a grid, then what needs so many rectangles?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Perhaps you can draw it in a separate thread and pass the resulting picture back to be used as a background for the Window?
I are Troll
|
|
|
|