开发者

What would be the math symbol for representing a fraction?

I would like to shown 2/3 (i.e. 2 divided by 3) in a HTML format and I don't want to u开发者_StackOverflow社区se /. What would be the right symbol to format fractions/division using HTML?


Judging by your comments, it looks like you're specifically asking how to display fractions. If that's the case, many fractions are defined as HTML entities. As an example, a few of those entities are:

½ ¼ ⅛ ⅔ ⅖ ¾ ⅜

Result:

½ ¼ ⅛ ⅔ ⅖ ¾ ⅜

Note that not all browsers support those named entities, but you could use their Unicode values instead. If you want to be able to display any fraction and not just the ones that have entities, you can use the fraction slash entity, ⁄ ( ⁄ ). This character overlaps pixels from the preceding and following characters to make a very neat fraction. It's best used when combined with superscript and subscript numbers:

<sup>39</sup>&frasl;<sub>40</sub>

Result:

3940

Further reading:
http://changelog.ca/log/2008/07/01/writing_fractions_in_html

If the font you're using supports it, you may also be able to paste the subscript and superscript numbers directly into your HTML from an application like charmap.exe. See Konrad Rudolph's excellent answer for an example.


To generate the division sign ÷, type &divide; or &#247;


Use the entity &#247;

÷

HTML ASCII Characters


Have a look at this article: Writing Fractions in HTML

Since you want to see denominator below the numerator you can use the code:

<sup>2</sup>
&frasl;
<sub>3</sub>

Which will look like:

23


By the way, you don’t necessarily resort to HTML tags and HTML entities (arguably, the <sup> and <sub> tags aren’t well-suited for the task). You can also rely solely on Unicode:

Predefined vulgar fractions:

  • U+00BC ¼
  • U+00BD ½
  • U+00BE ¾
  • U+2153 ⅓

And then there’s the fraction slash (U+2044, ⁄) and the superscript and subscript numbers at positions U+00B9, U+00B2, U+00B3 and starting at U+2070. Using these, you can get arbitrary vulgar fractions:

⁴⁵⁄₂₃

This was all written as seen on the screen (look at the source if you don’t believe me!), no HTML code whatsoever. However, not many fonts support all of the number forms so the HTML variant may be more usable in practice.


Since you prefer to display in numerator/denominator format, use &frasl; in conjunction with HTML sup and sub

Example:

<sup>4</sup> &frasl; <sub>9</sub>  will give you

49

To be more safe, you can use the decimal variant: &#8260;

Example:

<sup>4</sup> &#8260; <sub>9</sub>  will give you

49


You could use MathML to write more complex maths formulas and equations.

http://www.mozilla.org/projects/mathml/demo/basics.xhtml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜