|
|
It's floating point data: it's stored in binary, not decimal, and 0.1 decimal is not a "precise" value in floating point format: 15. Floating Point Arithmetic: Issues and Limitations[^]
If you format your output to two decimal places, it'll always look the same:
for (float i = -5.0f; i < 5.0f; i += 0.1f)
{
Console.WriteLine($"{i:0.00}");
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
modified 13-Sep-20 10:19am.
|
|
|
|
|
Isawyouoo wrote: 0.1f The bullshit is right here. There is no float with the exact value of 0.1, so the nice-looking results are at best misleading.
|
|
|
|
|
so what is the best way to make the loop generate those numbers correctly? just by i.ToString("0.00")
|
|
|
|
|
That doesn't affect the actual number, just the string representation of it.
Read the links Richard and I gave you.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Depends on what you want with them. If just printing them with fewer decimals is good enough, great. Or maybe it's an occasional for decimal floating point (in C# with the handy decimal type, though a bit slow), or decimal fixed point (store eg -49 instead of -4.9, and handle the details of the arithmetic manually).
|
|
|
|
|
Did you even stop to think about the problem before you lost your mind?
How many floating point numbers are there in any range of values? Infinite.
How do you represent an infinite number of values in a finite number of bits? You don't, but to get the largest usable range possible, you have to make sacrifices and put up with limits on precision.
...and you just ran into one of those limits.
Seriously, read those links and your expand your understanding instead of getting pissed over something you don't understand.
|
|
|
|
|
thank god you people, I've lost my mind one moment, I was gonna throw my laptop from the window
|
|
|
|
|
I need to determine whether each character in the first string can be uniquely replaced by a character in the second string so that the two strings are equal.
Like this:
for "eef" and "ddg"
Result :
True e => d
f =>g
If I have: "efe" and "ddg" the result is "False" because "e" it has "d" and "g". (strings are equal in length)
I need help with the starting point, I made an array to store the characters from input strings and I was thinking to use IndexOf method after that, to return the indexof each character and compare it with the second string. I'm not sure how to implement this.
modified 13-Sep-20 10:21am.
|
|
|
|
|
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?
What help do you need?
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I need help with the starting point, I made an array to store the characters from input strings and I was thinking to use IndexOf method after that, to return the indexof each character and compare it with the second string. I'm not sure how to implement this.
|
|
|
|
|
Think about how you would do it manually, with a pencil and paper.
When you have that down pat, the code should be pretty easy.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Make an array with a position for each character code, each element a character and a bool, initialized to nul and true. Scan the two input strings S1 and S2 in parallel. Use the S1 char as index in your new array. If its char is still nul, change it to the S2 char. If it is something else, but different from the S2 char, set the bool to false. After reaching the end of S1/S2, if there are any entry in you new array with the bool set to false, the result is false.
I am sure that your professor will accept this solution method for your homework.
|
|
|
|
|
Strings can be treated as an array of characters so you don't have to create "input arrays".
string a = "eef";
string b = "ddg";
Dictionary<char, <list<char>> dic = new ...
if ( a.Length == b.Length ) {
for ( int i = 0; i < a.Length; i++ ) {
if ( dic.ContainsKey( a[i] ) {
}
}
}
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hello, and thank you for your time to look out my question.
I forgot to say that I have to use only System, not list or dictionary, LINQ, and others. The course assignment requirements. I think that is more about the logic
|
|
|
|
|
Hi Friends,
I have a scenario where need to generate WordProcessing Report
Here is my template sample below
First Name: «FirstName»
Last Name: «LastName»
Here First Name and Last Name are keys and corresponding Merge-fields are («FirstName» & «LastName»)
Now I have to generate a report where these key and merge-fields need to repeat number of times according to the Employee record. Example if there are fice employees in database, i need to show all five employees record one after other with FirstName and LastName in sequence.
I tried with below code. But this wont help because the key and data value does not show as per template configuration.
Can you please tell me how can i achieve this in C#?
Thanks in advance.
|
|
|
|
|
You could achieve it faster in MS Word.
|
|
|
|
|
|
Search and replace; should be simple enough. What part of the code are you struggling with?
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
For some reason when I display icons in the ListView control, they are slightly fuzzy, or blurred.
I'm taking the icons from executable files and displaying them next to the filename, like Windows File Explorer.
But in Windows File Explorer, the icons are crystal clear.
I have the color depth of the ListView image list set to 32 bits.
Anyone have an idea?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Sounds more like a resolution problem. Icons do not rescale well. Can you access different size icons from the exe?
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Yes, I can probably extract different sizes. The icons are being extracted by the ExtractIconEx Win32 function in a native DLL.
Does the ListView control offer the capability to display the same icon(s) at different sizes? So far I've only seen one small size and one large size.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard Andrew x64 wrote: Does the ListView control offer the capability to display the same icon(s) at different sizes? Beyond my pay grade, I'm sorry. Ask an expert.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
All I can do is ask everybody and hope an expert answers.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I assume this is related to your other question in the C/C++ forum. Are you sure you are extracting the correct icon, i.e. having the size that matches the ImageList properties?
|
|
|
|