# Problem with working precision

I have tried to resolve the problem of the following link How can I solve precision problem

I can tell the problem described in that link shortly here, It's no mater how many precision is there after decimal(.) the result should be 2 or 3 precision after decimal as per user requirement.e.g

N[10/3]
3


Output should be as per user wish precision as 2.

3.33
3.00


There I found NumberForm[] function as a solution, since the NumberForm[] function is wrap up the result, I can't get the result as number out of it.

I tried like this

NumberForm[N[10/3],{4,2}]
NumberForm[3, {4, 2}]


Output am getting is

3.33
3.00


But when I try to do further operation, it's not computing

NumberForm[N[10/3], {4, 2}] + 1
NumberForm[3, {4, 2}] + 1


Output

1+3.33
1+3.00


I tried other way also which follows

ToExpression[ToString[NumberForm[3, {4, 2}]]]


OutPut

3.


but I need output as 3.00. Help me to find the solution.

-

Is SetAccuracy what you want?

a = N[10/3, {∞, 3}]


3.33

b = 33


3.00

a + 1


4.33

b + 1


4.00

394.9856743


394.99

Please note Accuracy is a different concept from Precision.

-

Use the $PrePrint global parameter: $PrePrint = If[MatchQ[#, _?NumericQ], NumberForm[#, {4, 2}], #] &;


Note: if you dont want the way rationals will be represented after setting the global variable (e.g. $3.00/4.00$) then use this instead

\$PrePrint = If[MatchQ[#, Except[_Rational,_?NumericQ]], NumberForm[#, {4, 2}], #] &;


Update:

if you just want it for the InputField command try this instead

InputField[Dynamic[ToString@NumberForm[b, {4, 2}]], String]

-
I have problem with your answer, I need to give the result to InputField the output I got is not I expected.b=3 InputField[Dynamic[b], Number]. I got result 3 alone in InputField not 3.00 –  niren Apr 24 '13 at 9:59
@niren Indeed but you didn't ask that ... –  Spawn1701D Apr 24 '13 at 10:06
@niren This is closer to what you really want: InputField[Dynamic[ToString@NumberForm[b, {4, 2}]], String] –  Spawn1701D Apr 24 '13 at 10:11
I want only Number in InputField, Since the result from the InputField will go for further calculation. –  niren Apr 24 '13 at 10:16
@niren but inside the input field you cant do any calculations just input a number. You have to explain exactly what you want. –  Spawn1701D Apr 24 '13 at 10:19