Friday 15 January 2010

c# - Parsing a fraction to double -


I want to parse the stored part in a string (eg "2/13") I repeat the parsing code But my only question is where should this code be best if I can double use it. For this purpose () function () Is it possible to do this? If double Purse () can not be used because it's about writing an extension method? Or any other way?

I do not want to write an excerpt class because the conversion to repeat the fraction of the string once the operation is over (when the user first enters) and then the fraction strings will be abandoned.

"... after that the fraction string will be removed."

You can create fraction squares, with a static parse method that takes a string and returns a double return. Public Static Class Fraction {Public Static Double Pars (String in Well) {// Code String // To Pars and Calculate Return}}

Usage:

  double myvalue = fraction Purse ("2/13");  

Nothing is immediate, nothing is left ...

This approach definitely accepts that you do not care to keep original values On the basis of your mention (in the Yr question that you want to use "throwing" anatial string value to make the numerator)

If, otoh, you want to "hold" that condition Were (in the beginning of the two integers used to make the fraction N), then there would be a better way of going to a different non-stable class (actually a structure might be better) in this case then you lose no precise, because the future arithmetic functions are used by the examples of this structure Two basic precise integral state values ​​stored in these areas can be coded to be used.


No comments:

Post a Comment