Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > de.comp.lang.php > #4856

Re: (s)printf max width

From Claus Reibenstein <creibens@gmail.com>
Newsgroups de.comp.lang.php
Subject Re: (s)printf max width
Date 2022-09-17 16:30 +0200
Message-ID <jom3vbFu2kvU1@mid.individual.net> (permalink)
References <tg4j8i$op8$1@gioia.aioe.org>

Show all headers | View raw


Andreas Neumann schrieb am 17.09.2022 um 15:49:

> [(s)printf]
>
> Meine Aufgabenstellung: Die floating-point number bewegt sich zwischen 0 und
> 99. Für Zahlen <10 möchte ich eine Ausgabe von z.B. "7.2", für >=10 möchte
> ich eine Ausgabe ohne Dezimalstellen, z.B "24". In beiden Fällen also mit
> nicht mehr als 2 Stellen.

"%.2g" sollte genau das tun, was Du suchst.

Weitere Details zum Format-String findest Du z.B. unter
<https://www.php.net/manual/en/function.printf.php>.

Gruß
Claus

Back to de.comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

(s)printf max width Andreas Neumann <an5275@sedo.com> - 2022-09-17 15:49 +0200
  Re: (s)printf max width Claus Reibenstein <creibens@gmail.com> - 2022-09-17 16:30 +0200
    Re: (s)printf max width Claus Reibenstein <creibens@gmail.com> - 2022-09-17 16:47 +0200
    Re: (s)printf max width Andreas Neumann <an5275@sedo.com> - 2022-09-17 17:15 +0200

csiph-web