Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display a negative symbol in .NET?

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?

like image 892
NotDan Avatar asked Aug 26 '09 01:08

NotDan


People also ask

How do you make a negative sign on a keyboard?

Type the following key combination : ⌥ Alt + ⇧ Shift + = : ± The technique: Keep the Alt ⌥ and ⇧ Shift keys pressed, then type on the key = , which will bring up the "plus or minus" sign : ± at the desired location.


5 Answers

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
like image 187
Darko Z Avatar answered Sep 30 '22 03:09

Darko Z


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 
like image 29
SLaks Avatar answered Sep 30 '22 02:09

SLaks


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

like image 31
STW Avatar answered Sep 30 '22 02:09

STW


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

like image 28
Anderson Imes Avatar answered Sep 30 '22 04:09

Anderson Imes


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

like image 26
yoyoyoyosef Avatar answered Sep 30 '22 04:09

yoyoyoyosef