By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,669 Members | 1,671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,669 IT Pros & Developers. It's quick & easy.

how to print out fractions

P: n/a
Hi,

Can someone supply a code example of displaying a string with a fractional
part, say 5 and 7 16ths.

I cannot find an example of how to use the Encoding object (if that is what
you use).

thanks,
Mori
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Mori,

I generally would stay away from this kind of thing. The reason is that
no matter what, you will never be able to have a character set that can
include all of the fractions that are possible. Not only are there space
considerations, but it is mathematically impossible (the range of numbers
for the top and bottom numbers are both infinite, and there is nothing on a
machine that can represent that).

This is why you are better of using some other representation.

--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mori" <mo**@design-paradigm.co.uk> wrote in message
news:e0*************@TK2MSFTNGP11.phx.gbl...
Nicholas,

Yes, as a single character.

There are a few fractions in the Microsoft Sans Serif font, so I have been
able to display those fine in Labels etc.

I was thinking of creating my own font for the program but I will also be
outputting to a Word document, so whoever reads the document will have to
have that font installed on their machine.

I just thought have one a character fraction is better looking than 7/16.

Thanks for your time,
Mori
"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...
Mori,

Do you mean as a single character? I don't think that you can do this
for any fraction you wish (as far as I know), because character sets have certain fractions pre-defined. If it is a rich text box, then you might

be
able to superscript and subscript some text, and that will give you the
result you want, but I don't know if an Encoding object will help in this case.

What are you using to display the fraction?
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mori" <mo**@design-paradigm.co.uk> wrote in message
news:e$**************@TK2MSFTNGP12.phx.gbl...
Hi,

Can someone supply a code example of displaying a string with a

fractional part, say 5 and 7 16ths.

I cannot find an example of how to use the Encoding object (if that is

what
you use).

thanks,
Mori



Nov 15 '05 #2

P: n/a
C# doesn't explicitly (afaik) have a means for managing rational
numbers as distinct object. Encoder supports the use of fractions,
but that's just for accurate specification, not because it really has
that much of a clue.

If you're looking for intelligent output, i.e. if you've given the
fraction
5 4/16ths, and want to get back 5 1/4th, you need to implement a
fraction class that can normalize the fraction, i.e. reduce it. The
following link is to C++ code, but the Normalization function provided
should give you an idea of whats needed.

MMM

http://www.codeproject.com/useritems/cfraction.asp
"Mori" <mo**@design-paradigm.co.uk> wrote in message news:<e$**************@TK2MSFTNGP12.phx.gbl>...
Hi,

Can someone supply a code example of displaying a string with a fractional
part, say 5 and 7 16ths.

I cannot find an example of how to use the Encoding object (if that is what
you use).

thanks,
Mori

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.