There are two kinds of inexact numbers in Mathematica:
Machine numbers are directly supported by your CPU (hence the name), so they are extremely fast to work with. However, they do no include precision tracking.
Arithmetic for arbitrary precision numbers is implemented in software, and it is much slower. But arbitrary precision numbers use precision tracking and can have any number of digits.
These types of numbers are "sticky" like this:
2. is a machine number, therefore all numerical operations (including
N) done with it result in a machine number.
To convert between these various types of numbers, you can use
SetPrecision[2.5, 10] (* machine number -> arbitrary precision *)
(* 2.500000000 *)
SetPrecision[2.5, Infinity] (* machine number -> exact *)
(* 5/2 *)
I want my results to give up to 10 digits (first example) and at the same time I want to use machine float numbers (second example) so that the numerical evaluation is fast. Is there a way to fix this?
Not really. All you can do is truncate the final result to 10 digits. You cannot force machine arithmetic to use 10 digits instead of ~16. It is implemented in hardware and it cannot be changed.
If you want to see what happens when you calculate with exactly 10 digits, use the ComputerArithmetic package. It is designed exactly for such exploration. However, it is much slower than even the built-in arbitrary precision arithmetic.
Note that in Mathematica it isn't really possible to do 10-digit arithmetic even with arbitrary precision numbers. Mathematica will track the precision, thus the result you get after operating together two 10-digit numbers won't be exactly 10-digit.
1.12`10 - 1.1`10
(* 0.020000000 *)
(* 7.95468 *)
Update: Carl Woll points out that this above is not correct.
It is possible to emulate fixed precision with arbitrary precision numbers by blocking