How to draw the 1/2 symbol

  • Thread starter Thread starter Ray Martin
  • Start date Start date
R

Ray Martin

The "1/2" symbol is 00BD in Unicode, or 189 in Decimal or 00BD in Hex

Can someone post some simple code using Drawstring or Drawimage to draw
this. I am printing numbers and would like the 1.5 to print as 1 1/2, but
using the "1/2" symbol instead of the 3 characters "1" "/" "2"

Thanks
 
One way to do this is as follows.

float val = 1.5F;
if ((val % 1.0) == 0.5)
{
string text = String.Format("{0} \u00BD", (int)val);
graphics.DrawString(text, this.Font, Brushes.Black, 0, 0);
}
 
Thanks. That's a clever way. I also realized that the following works for
otthers that may need to do this and created the following function:


Private Function format_qty(ByVal qty As Decimal) As String

Dim control As Integer

Dim difference As Decimal

control = Decimal.Truncate(qty)

difference = qty - control

If Math.Abs(difference) > 0.49 And Math.Abs(difference) < 0.51 Then

If control = 0 Then

format_qty = Chr(189)

Else

format_qty = control.ToString + Chr(189)

End If

Else

format_qty = qty.ToString

End If

End Function
 
Back
Top