How you do it depends on what you are producing: For web applications you could use a validator:
<asp:TextBox ID="NumericTextBox" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="NumericOnlyValidator" runat="server" ControlToValidate="TextBox1" ErrorMessage="Enter a valid number" ValidationExpression="^\d$"></asp:RegularExpressionValidator>
Or, you could do it with Javascript, and prevent entry of non-numerics:
function isNumeric(evt)
{
var c = (evt.which) ? evt.which : event.keyCode
if ((c >= '0' && c <= '9') || c == '.' )
return true;
return false;
}
MyTextBox.Attributes.Add("onkeypress","return isNumeric(event)");
For a Winforms, I would use a NumericUpDown.