Karim Belabas on Mon, 02 Sep 2024 17:43:31 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: How to show few decimal digits of a real number?


* Georgi Guninski [2024-09-02 17:40]:
> I have real number A and want to show only few fractional digits,
> how to do it directly without floor/round?
> 
> The following doesn't work:
> ? precision(Pi)
> %3 = 38
> ? precision(Pi,2)
> %4 = 3.141592653589793239

See ??printf

  ? printf("%.2f", Pi)
  3.14

Cheers,

    K.B.
-- 
Pr. Karim Belabas, U. Bordeaux, Vice-président en charge du Numérique
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/