|
Just a minor point - in numeric terms, 1120.00120000 is exactly the same as 1120.0012. If you're doing a calculation using a decimal then it doesn't make much sense to round trim it.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Indeed, though there is a difference in some situations, such as when using ToString(). Try running this:
string strD = "192.0205000";
Decimal D = Decimal.Parse(strD);
MessageBox.Show(D.ToString());
I never knew that the Decimal data type actually maintains the trailing zeroes.
|
|
|
|
|
|
Excellent question! And thanks for providing the answer. I had no idea the Decimal data type stores trailing zeroes.
jojoba2011 wrote: PLZ HELP !
Just a bit of friendly advice... avoid using uppercase when not necessary, don't beg for help, and don't shorten words (e.g., "PLZ") except for common acronyms. To many people here at Code Project, it appears unprofessional. Other than that, though, great question.
EDIT: It appears your answer is incorrect.
|
|
|
|
|
This is merely a quirk of the "G" format; when ToString ing a Decimal, use something along the lines of d.ToString ( "#.###############" ) .
|
|
|
|
|
Good call. One can also use:
d.ToString("G29");
|
|
|
|
|
That's basically what the default is and I don't think it works.
|
|
|
|
|
|
|
After reading what everybody has said, I think you want this:
Decimal d = Decimal.Parse(Decimal.Parse("192.0205000").ToString("G29"));
|
|
|
|
|
Hello!
I want to do some custom drawing on my windows forms application, which involves connecting my own defined controls with lines.
That should be easy, but I couldn't figure a way to draw these lines as objects/controls, so I can define events for them. I am also thinking of not getting too greedy with the memory.
I appreciate any suggestion.
Thank you!
|
|
|
|
|
This[^] might be a good beginning.
|
|
|
|
|
Here's a line control that I wrote. Real simple, and it has a LineClicked event.
marois-consulting.com/files/LineControl.zip
Everything makes sense in someone's mind
|
|
|
|
|
I have a text box and a crystal report viewer in a windows form.
As user types in some text in text box, it should immediately display in report viewer. I have done this, but I have problem here, that is "If user types too quickly then refreshing of the preview screen is fine, but if user type slowly then text is lost"
I am not able to find a solution to this problem.
I tried with multithreading, with timer but could not able to implement it.
can someone please help me in this?
Thanks in advance
|
|
|
|
|
What? The text in the TextBox? Are you clearing it? Why?
At any rate, I don't think I would implement it that way. I would have the user enter the text and then press a Button to get the preview. I find producing unnecessary previews and such to be wasteful and irritating.
|
|
|
|
|
Mahesh_Blr wrote: "If user types too quickly then refreshing of the preview screen is fine, but if user type slowly then text is lost"
Can you not refresh your report in the text box's keyup/keydown event?
|
|
|
|
|
In my program, I have an array of numbers (total number of modules that can be connected to a tracker) and an array of sums (number of modules that has to be mounted on a roof surface).
Let's suppose:
int[] intConnectables = {24, 22, 20, 16, 12, 11, 10, 7, 6}
int[] intRoofSurfaces = {43, 38, 27, 11}
The script has to group the connectables so that every number is used and there are the groups so every total adds up. If there exists a valid combination, I put the system in a seperate set (in the end that set would contain all valid combinations).
e.g.
24+12+7 = 43 | 22+10+6 = 38 | 20+16 = 27 | 11 = 11
Afterwards, I'll have to know wich element of Connectables belongs to wich group (e.g. 22 belongs to the 2nd group wich adds up to 38).
Any ideas?
Thanks in advance!
modified on Wednesday, April 28, 2010 11:05 AM
|
|
|
|
|
Are you looking for the algorithm (subset sum?) or a way to get the group number back from an element (maybe use parallel arrays, or a dictionary if you're going to move the elements)?
Or something else?
|
|
|
|
|
Actually the algorithm. Each roof surface is oriented and inclined in a specific angle. The array I use is the grouping of the roof surfaces to these fields. The orientations and inclinations have to be transferred to the "connectables" afterwards to calculate generated power. That's why I have to know wich element of the intConnectables belongs to wich sum in intRoofSurfaces.
|
|
|
|
|
Can you use the connectables once per roof surface or just once (across all roof surfaces)?
For now I'm guessing the latter..
And you must use all of them?
You could maybe (in pseudo code):
(!!untested!!)
bool Solve(int i)
{
if (i == numberOfConnectables + 1)
return true;
for each RoofSurface
add Connectable[i] to the RoofSurface
if (RoofSurface.Sum <= RoofSurface.Target)
{
if (Solve(i + 1))
return true
}
remove Connectable[i] from the RoofSurface
endfor
return false
}
Just an idea, I'll go test it in a moment
|
|
|
|
|
Just once across all roof surfaces. In the end I need to know if the "puzzle" can be solved and -if so- wich connectable belongs to wich roof surface.
The array intRoofSurfaces contains the targets. The most important thing I need to know is if there is a possibility to divide the elements of intConnectables[] into n groups where n is the number of elements in intRoofSurfaces. If it proves to be possible, I need to know for every element in intConnectables[] to wich element of intRoofSurfaces[] it is connected.
I know, I'm being a little picky right now, but I really need to get it before I can code the next parts of my program.
The following is just informative, so don't take it in consideration when posting your ideas just yet... Therefore I'll put it in a smaller font.
I have a set with a whole bunch of combinations (arrays intConnectables[]). Every combination will be checked. A few steps later, the roof surfaces are ungrouped and I'll have to do a reversed algorithm. More or less, because a connetable will now be usable across roof surfaces.
e.g.
The grouped roof surface has to contain 28 modules and it exists of 3 roof surfaces: 15, 7 and 6 modules. There are 4 connactables assigned, 9, 8, 6 and 5 modules.
intConnectables[] = {9, 8, 6, 5}
intSeperateRoofSurfaces[] = {15, 7, 6}
Then I would have to get a result like this:
9 + 6 = 15 | 7 [from 8] = 7 | 5 + 1 [from 8] = 6
So the connectable of 8 has been split into 7 and 1.
Just informative...
|
|
|
|
|
Ok can you verify this please?
Connectables = { 24, 22, 20, 17, 12, 11, 10, 7, 6 }
RoofSurfaces = { 43, 38, 37, 11 }
Answer = yes, { 0, 1, 2, 2, 0, 3, 1, 0, 1}
|
|
|
|
|
Works like a charm! Thanks
|
|
|
|
|
Tested, works (for the problem as I understood it, anyway):
static class Solver
{
static int[] RoofSurfaces, Connectables, Sums, AssignedTo;
public static int[] Solve(int[] connectables, int[] roofSurfaces)
{
RoofSurfaces = roofSurfaces;
Connectables = connectables;
Sums = new int[roofSurfaces.Length];
AssignedTo = new int[connectables.Length];
for (int i = 0; i < AssignedTo.Length; i++)
AssignedTo[i] = -1;
if (solve(0))
return AssignedTo;
return null;
}
static bool solve(int i)
{
if (i == Connectables.Length)
return true;
for (int k = 0; k < Sums.Length; k++)
{
Sums[k] += Connectables[i];
AssignedTo[i] = k;
if (Sums[k] <= RoofSurfaces[k])
{
if (solve(i + 1))
return true;
}
Sums[k] -= Connectables[i];
AssignedTo[i] = -1;
}
return false;
}
}
If there is a solution, it returns an array with the number of the RoofSurface that each Connectable is in, otherwise it returns null.
edit: it may not be the coding style you like etc etc, I'm not trying to set a good example here, I just made this in a couple of minutes to Just Work without looking at the style too closely.
The -1's were just useful for debugging - you don't actually need them (the variable i already determines which entries are valid)
modified on Wednesday, April 28, 2010 11:03 AM
|
|
|
|
|
I don't mind the coding style, mine isn't perfect as well. But at least I have a good idea of how to solve this thing...
Big thanks!
|
|
|
|
|