In my project I am converting some vb.net to c# and I came to this line:
int thisdigit = Fix(countervalue / (Math.Pow(10, (numdigits - j - 1)))) - Fix(countervalue / (Math.Pow(10, (numdigits - j)))) * 10;
But I get the error:
The name 'Fix' does not exist in the current context
How do I fix this? I can't understand why Fix() wouldn't exist.
But if I used Math.Truncate()
instead, well, that doesn't work because thisdigit
is an int
.
How could I change that?
Here is my original vb.net code:
dim dg as int
dg = Fix(value / (10 ^ (digits - j - 1))) - Fix(value / (10 ^ (digits - j))) * 10
Here is a link to what I'm trying to convert: https://www.developerfusion.com/code/3734/aspnet-graphical-page-hit-counter/
The code works in my vb.net projects. I've run my converted code through the debugger, and the only place I can see any problem is with this line.
I came up with this, too:
double thisdigit = Math.Truncate((double)(countervalue / (10 ^ (numdigits - j - 1)))) - Math.Truncate(((double)(countervalue / (10 ^ (numdigits - j))) * 10));
I don't really understand why this is so convoluted..
The original code seems to draw a counter, one digit at a time:
dim j as Integer, dg as Integer
for j = 0 to (digits-1)
' Extract digit from value
dg = fix(value / (10^(digits - j - 1))) - fix(value / (10^(digits - j)))*10
' Add digit to the output graphic
g.drawimage(i, New rectangle(j*dgwidth, 0, dgwidth, dgheight), New rectangle(dg*dgwidth, 0, dgwidth, dgheight), GraphicsUnit.Pixel)
next j
But surely it would just be easier to do something like:
int pageCounter = 7234283;
string toDraw = pageCounter.ToString();
for(int i = 0; i < toDraw.Length; i++)
someGraphics.DrawString(toDraw.Substring(i, 1), someFont, someBrush, new PointF(i * 10.0f, 0));
Or perhaps:
int pageCounter = 7234283;
string toDraw = pageCounter.ToString();
PointF p = new PointF(0.0f, 0.0f);
foreach(char c in toDraw){
someGraphics.DrawString(c.ToString(), someFont, someBrush, p);
p.X += 10.0f;
}