473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to print out fractions

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
2 7003
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: skip | last post by:
I'm looking for a solution (or ideas about a solution) to the problem that strftime(3) and strptime(3) don't understand time increments of less than one second. Most operating systems can provide...
2
by: karp | last post by:
Lets say I have the following class in order to add two fractions, class Fraction{ public: Fractions::Fraction(int numer = 0, int denom = 1) { valeurNumerateur = numer; valeurDenominateur =...
33
by: selowitch | last post by:
I've been searching in vain for a way to present typographically correct fractions (not resorting to <sup> and <sub> tags) but have been frustrated by the fact that the glyphs for one-half,...
5
by: Steffen | last post by:
Hi, is it possible to have two fractions, which (mathematically) have the order a/b < c/d (a,b,c,d integers), but when (correctly) converted into floating point representation just have the...
2
by: Just Me | last post by:
I need a numerical updown control that displays fractions. If the increment is 1/16 it would display 1/16, 1/32, 3/16, 1/4... I thought I might inherit from a NumericalUpDown control and place...
4
by: Bob | last post by:
Hi All, Was wondering if in C# there is an elegant way of displaying and or calculating fractions. The case: we have an app that measures/slices dices etc and all our internal measures and...
1
by: Semajthewise | last post by:
Here it is cleaned up a little more. Here's what this code does. It will take 2 fractions and add, subtract, multiply, or divide them. The user enters the fractions to be calculated into two...
5
by: gubbachchi | last post by:
Hi all, How to convert the fractions into decimals and vice versa in php. I have a form, where the user will enter fractions in the text boxes such as "1 1/2", "1 1/4" and so on. I need to store...
0
by: Paddy | last post by:
(From: http://paddy3118.blogspot.com/2008/09/python-fractions-issue.html) There seems to be a problem/difference in calculating with the new fractions module when comparing Python 26rc2 and 30rc1...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.