It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am trying to convert this python instruction to C#
int(round(time.time()))
But I cannot figure out what it does exactly.
You need to use UtcNow as opposed to Now or else you will get an answer offset by your timezone.
TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
int timestamp = (int) t.TotalSeconds;
time.time() will return the current time as a float which represents seconds since 1/1/1970, round() will round that float to the nearest integer value, and int() will convert the value to the integer type.
For example:
>>> time.time()
1351702579.645324
>>> round(time.time())
1351702580.0
>>> int(round(time.time()))
1351702580
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
i have following linq used in my application
var FinalSubExpired = subExpired.Where(e => (DateTime.Now - Convert.ToDateTime(e.AreasOfLawTillDate)).TotalDays <= 30 ).ToList();
which returns the total days with negative values, i need to remove that negative sign from that total days. how can i do that by modifying this linq?
Please help.
var FinalSubExpired = subExpired.Where(e => Math.Abs((DateTime.Now - Convert.ToDateTime(e.AreasOfLawTillDate)).TotalDays) <= 30).ToList();
that should do the trick
try and use Math.Abs inside your Linq query, as:
var FinalSubExpired = subExpired.Where(e => (Math.Abs(DateTime.Now - Convert.ToDateTime(e.AreasOfLawTillDate)).TotalDays) <= 30 ).ToList();
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I try just an old VB application in c# to convert, while I've encountered this line of code:
Mid(strData, intPosition + 1, intLenght) = strValue
How can it be translated into c#?
You would have to combine Remove and Insert, something like:
strData.Remove(intPosition, intLenght).Insert(intPosition, strValue);
The above assumes that the length of strValue was equal to intLenght. If strValue might be longer, then to replicate the Mid statement, we would need to do:
strData.Remove(intPosition, intLenght)
.Insert(intPosition, strValue.Substring(0, intLenght));
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How can I round up values like this:
1.001 => 2
3.3 => 4
Means if the number has fractional part than i want the smallest integer number greater than the number ?
I used Math.Ceiling() but is not helping. How can i do this ?
Math.Ceiling will work. can you tell what its not working ? in term of any errors or returned result.
var returnVal=Math.Ceiling(yourValue);
Use Math.Ceiling() method.
Returns the smallest integer greater than or equal to the specified
number.
var i = Math.Ceiling(1.001);
var j = Math.Ceiling(3.3);
Console.WriteLine(i);
Console.WriteLine(j);
Output:
2
4
Math.Ceiling(value);
Should work.
double x;
x = Math.Ceiling(5.2) ;//Result; 6
x = Math.Ceiling(5.7) ;//Result; 6
x = Math.Ceiling(-5.2) ;//Result;-5
x = Math.Ceiling(-5.7) ;//Result;-5
This is a simple example. How can't you use it? Maybe you miss to assign a variable to
Math.Ceiling();
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How can I format this decimal: 123456789012345678
to a string "1.234.567.890,12345678"?
Thanks!
Look here for additional information about custom formats of numbers (of any type)
public string SpecialFormatDecimal(decimal input)
{
return (input / 100000000).ToString("#,##0.00000000", System.Globalization.CultureInfo.GetCultureInfo("en-US"));
}
A simple search on google showed the answer right away.
If you need local decimal point and thousand separator you can leave out the CultureInfo.
Casperah answer is great, but don't forget, that you can use standard numeric format
public string SpecialFormatDecimal(decimal input)
{
return (input / 100000000).ToString("N8");
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Alright, so I've tried to search for it, and yes, I found the answer, but not the explanation of it, I'd like to know the explanation of the following result:
float fib(int num)
{
float result;
if (num==1)
result=0;
else
{
if (num==2)
result=1;
else
result=fib(num-1)+fib(num-2);
}
return result;
}
Start here: http://en.wikipedia.org/wiki/Recursion
Then go here: http://en.wikipedia.org/wiki/Fibbonaci_Series
The method called fib() calls itself in certain cases, and does not call itself in other cases (known as base cases).