views:

428

answers:

7

I want to display a negative symbol from a string in .NET. I want a string that represents an equation that looks something like this:

7--5=12

But when displayed, I want the 2nd minus sign to be slightly raised so it looks more natural as a negative sign instead of just 2 minus signs in a row.

Is this possible?

+9  A: 

Not sure if theres a character for what you want but a simple solution (and one that would be easily understood and implemented) would be to surround your negative number in brackets:

7 - (-5) = 13
Darko Z
This is the most typographically robust solution.
Greg Hewgill
This is good, except the target audience is for elementary students. I think they will understand the raised minus sign over this format. Otherwise, this is what I would probably do.
NotDan
+2  A: 

Provided that you're using unicode you can use a true minus sign, "−" (U+2212) rather than a hyphen-minus, "-" (U+002D). Just be aware that it's not ASCII compatible

Here's your example showing them:

7 - −5=13

Also, here's some fun wiki-articles on all sorts of dash-hyphen-minus lines: http://en.wikipedia.org/wiki/Dash#Common_dashes http://en.wikipedia.org/wiki/Minus_sign#Character_codes

STW
+7  A: 

Use the Unicode character SUPERSCRIPT MINUS (U+207B) .

For example:

7-⁻5 = 13 

EDIT: Or, with a MINUS SIGN (U+2212) for the minus:

7 − ⁻5 = 13 
SLaks
It's what was asked for... but gaw that's ugly :)
STW
it would look better if you used a MINUS SIGN (U+2212) or en dash surrounded by spaces for the first minus
yoyoyoyosef
Yes, good idea.
SLaks
A: 

You can use the Unicode character U+2212 (Minus Sign): 7-−5=13

In the font I'm using, the minus sign is displayed slightly raised relative to the dash. Your results may vary.

Greg Hewgill
A: 

Unicode "superscript minus" http://www.fileformat.info/info/unicode/char/207b/index.htm

char c = '\u207b';
+2  A: 

This is a great resource on format strings in C#: SteveX Compiled - Format Strings

You can choose how a negative number is displayed by using a range expression for your format string. It's in the format:

{0:<PositiveFormat>;<NegativeFormat>;<ZeroFormat>}

For example, this is how to display a negative number in parenthesis and the word "Zero" for 0:

{0:#;(#);Zero}

Using this technique, I think you can try it with the superscript version of negative (which is ascii code U+207B) in the negative format string.

{0:#;⁻#;Zero}

HTH, Anderson

Anderson Imes
+1  A: 

Traditionally in math typography you use an en dash U+2013 or minus U+2212 (but not a hyphen!) for both binary (subtraction) and unary (negation) minus, and they are differentiated with spacing (spaces before and after a binary minus, no space between a unary minus and the number it negates).

But if you want to further distinguish the unary, I'd recommend substituting the superscript minus U+207B (but keep the spacing around the subtraction minus):

7 − ⁻5 = 13

yoyoyoyosef