|
[Stepping on my soapbox]
When dealing with floating point numbers, you should never assume that a number will be stored exactly. While some numbers can be stored exactly, most will not be.
From the cases I have encountered, too many people assume that a floating point number is good enough for exact numerical needs. But if the value 24.24999999999999 instead of 24.25 would be considered incorrect in your application, you should not be using floating point values.
Time and time again I have been called in to analyze why dollar values were coming in off by a penny or two (or more), and it has always* boiled down to the choice of using floating point representation to store exact values.
* Since 1992 I have encountered only 2 instances where the problem was an actual bug in the library.
|
|
|
|
|
The answer lies in the way implicit data type conversion works. Dividing and integer by and integer will never yeild a float or a double. So, InvItem.Price / 100 becomes 24 and not 24.25. I'm sure you understand the rest. To get correct answer do something like
<pre>( InvItem.Price / 100.0 ) * ( RI.Quantity / dbRecipeTotalQuantity )</pre>
|
|
|
|
|
I think InvItem.Price is int so 2425/100=24
you can write : InvItem.Price/100.0 to get correct result
|
|
|
|
|
I think InvItem.Price is int so 2425/100=24
you can write : InvItem.Price/100.0 to get correct result:
(this is tested and returns correct result):
double Quantity = 28.88887;
double dbRecipeTotalQuantity = 28.88887;
int Price = 2425;
double dbRecipeTotal = (Quantity / dbRecipeTotalQuantity) * (Price / 100.0);
|
|
|
|
|
I think the InvItem.Price is an integer,if so,the division will diacard the
part after decimal point automatically.
|
|
|
|
|
Hi, I'm trying to convert string to recurrence rule object, In the web forms it's done using the following code:
string rruleAsString = "Sample";
RecurrenceRule parsedRule;
RecurrenceRule.TryParse(rruleAsString, out parsedRule);
appointment.RecurrenceRule = parsedRule;
but in winforms it doesn't support "TryParse" !!!
please help me out
Thanx
K
|
|
|
|
|
mrkeivan wrote: winforms it doesn't support "TryParse"
And what did telerik tell you when you asked them?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
They suggested webform (I guess i didn't mention that I needed winform function)
anyway, I found it, the same function in a differenct class can be used here,
using Telerik.WinControls.UI.Scheduler.ICalendar;
CalHelper.TryParseRecurrenceRule(rruleAsString, out parsedRule);
|
|
|
|
|
I'm starting out with linq to xml and have a quick question:
I have the following xml-file:
<countries>
<country code="AF" iso="4">Afghanistan</country>
<country code="AL" iso="8">Albania</country>
<country code="DZ" iso="12">Algeria</country>
<country code="AS" iso="16">American Samoa</country>
<country code="AD" iso="20">Andorra</country>
.
.
.
How can I get a result containing all the country names by using a linq expression? I tried the following but it only gives me "Afghanistan":
XDocument xmlDoc = XDocument.Load("countries.xml");
var countries = from country in xmlDoc.Descendants("countries")
select new
{
Name = country.Element("country").Value,
};
Thanks for help!
|
|
|
|
|
Your Linq query is asking for the wrong thing from the XDocument.
The Descendents() method returns descendents of the object (in this case, the XDocument) which have the specified name (in this case 'countries'). So it is yielding a single enumerable element (because your XML Document has only one <countries> element).
What you really need is to get the 'country' descendents of the XDocument: from xmlDoc.Descendents("country") and then just get the Value property of the elements of the enumeration. Here's some code that works for you:
var countries = from country in xmlDoc.Descendants("country")
select new
{
Name = country.Value
};
|
|
|
|
|
Can you get a list of country:
<br />
XDocument xmlDoc = XDocument.Load("countries.xml");<br />
<br />
List<string> countries = from country in xmlDoc.Descendants("country")<br />
select new<br />
{<br />
Name = country.Value,<br />
};<br />
|
|
|
|
|
Hi,
How can i fetch the content of a website using c# (windows app). Purpose is to upload in our search engine.
Thanx
krishna
|
|
|
|
|
|
Hi,
Thanks for your info. what you said is true, only meta tag is enough... but in some situation we wont get i hope....for example type following tag in google "times of india sports" from that result check the third link "More Sports - Sports - The Times of India" which is the current updation of the website ...... how we can get those current updation results which is not mention in meta-tag. Even i may be wrong clear my doubt pls.
Thanks
krishna
|
|
|
|
|
|
Hi,
Thank you so much for your information, i will check those links and let u know....
Thanks
krishna
|
|
|
|
|
Errm no you don't. The use of meta tags is nowhere near enough.
"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
|
|
|
|
|
Meta tags often do not tell anything useful about the content of a page, they are often more like spam. I do not use them for such a purpose and nonetheless reach nice Google ranks for my pages.
|
|
|
|
|
Have a look at this[^] article on a fully featured search engine in C#.
"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
|
|
|
|
|
Wow...thts really cool....thanks alot for your information.
krishna
|
|
|
|
|
I want to convert text file to pdf file...Can anyone suggest...
|
|
|
|
|
|
I used to have a Perl script that did that -- maybe somoeone else has a copy.
Edit: See this[^].
modified on Tuesday, July 27, 2010 2:06 PM
|
|
|
|
|
|
I uploaded word doc and internally by using third party tool i converted it to pdf.Now, if i upload pdf file it should save as pdf file.I mean just to read a pdf file.Please suggest...
|
|
|
|