1
$\begingroup$

I am trying to format the user input in an InputField so that the input is formatted and then displayed back to the user, within the InputField.

InputField[ Dynamic[input],FieldSize->10]

where

If[StringMatchQ[input, NumberString], 
 NumberForm[ToExpression[input], DigitBlock -> 3, 
  NumberSeparator -> " "], "Enter a number"]

Is this possible?

$\endgroup$

1 Answer 1

1
$\begingroup$

Note: MMA format Integers automatically in your chosen format.

Try this:

input = "Enter a number";
InputField[Dynamic[input], FieldSize -> 10]
Button["Accept", 
 input = NumberForm[input, 20, DigitBlock -> 3, 
   NumberSeparator -> " "]]

enter image description here

Now enter a number:

enter image description here

Click the button:

![enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you @Daniel . What do you mean by "Chosen Format"? Is there a global setting to change all output's to a desired format, i.e. not scientific notation. I had hoped the inputfield simply had a 'styling' function to achieve this, but if it can be done globally that would be great! There is probably a similar solution whereby 'on insert of value -> call some function -> function then updates the value with NumberForm', that does not need a button, all working Dynamically. $\endgroup$ Commented Oct 11, 2024 at 9:56
  • $\begingroup$ Global setting under Appearance only allows me change how many digits it displays, not the format, i.e. not scientific notation. $\endgroup$ Commented Oct 11, 2024 at 10:14
  • $\begingroup$ With "Chosen Format" I mean the format specified in NumberForm[... $\endgroup$ Commented Oct 12, 2024 at 12:50

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.