MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Decimal comma on input

  • To: mathgroup at
  • Subject: [mg60531] Decimal comma on input
  • From: Cca <cca at>
  • Date: Mon, 19 Sep 2005 04:45:48 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

Here in Brazil our decimal separator is a comma. (This is the favoured convention in most non English-speaking countries.) We also put dots between each group of three digits. As an example, the number whose numeral is 


in USA is represented in Brazil as

NumberForm[1234.56789, DigitBlock->{3,3},
  NumberPoint->",", NumberSeparator->"."]

or also (following the SI)

NumberForm[1234.56789, DigitBlock->{3,3},
  NumberPoint->",", NumberSeparator->" "]

This said, it is natutal to ask: how to instruct Mathematica to recognize a decimal comma on input? My ad hoc
solution is shown below, but I would be very interested in knowing alternative approaches.

Instead of a "true" comma, I use one with hidden information, namely

TagBox[",", Identity, Editable->False, SyntaxForm->"."] // DisplayForm

with the following rule (which will work, of course, only in the expected contexts):

TagBox[",", Identity, Editable->False, SyntaxForm->"."], b_}], form_] := MakeExpression[StringJoin[a, ".", b], form]

Now we can try, for example, 2,3*3,5, 2,3+1,45, etc.
Finally, to make it easy to insert the decimal comma above I provide four ways to the user:

(1) a button:

ButtonBox[",", ButtonData-> 
   TagBox[",", Identity, Editable->False, SyntaxForm->"."]// DisplayForm

(2) a rule for InputAliases (which overrides \[InvisibleComma]);

(3) a keyboard shortcut, for which I add the following line to the file

Item[KeyEvent["KeypadDecimal"], FrontEndExecute[
TagBox[",", Identity, Editable->False, SyntaxForm->"."], After]}]]

(4) a menu command (not well tested yet):

     {Item["Decimal comma", 
     FrontEnd`NotebookWrite[FrontEnd`InputNotebook[], TagBox[",", Identity, Editable->False, SyntaxForm->"."], After]}]]}]]

Carlos César de Araújo
Gregos & Troianos Educacional
Belo Horizonte, MG, Brazil
(31) 3283-1122

  • Prev by Date: Re: Extracting coefficients for sinusoidals
  • Next by Date: Re: probability with simulation
  • Previous by thread: Re: 'Changing' parameters in an expression
  • Next by thread: Re: Decimal comma on input