sprintf bug

Петр

Новичок
sprintf bug

Здравствуйте!

Проблемка с sprintf

sprintf("%0-7u", 1); должно по идее вывести "1000000" , но выводит 1 с шестью пробелами после.

Вариант
sprintf("%'0-7u", 1); снова дает 1 с шестью пробелами.

НО

sprintf("%'2-7u", 1); Возвращает 1222222, как и должен

Есть у кого идеи по этому поводу? Может я не до конца понимаю синтаксис sprintf ?

P.S. PHP 5.1.6, UNIX
 

Гравицапа

elbirret elcno
Для строк (s) подобное работает и это можно использовать "как костыль".
Почему для чисел такое поведение не совсем понятно.

В багзилле по поводу sprintf + padding только этот баг найти удалось
http://bugs.php.net/bug.php?id=583
 

Гравицапа

elbirret elcno
Автор оригинала: tony2001
#include <stdio.h>

int main () {
printf("%0-7u", 1);
return 0;
}

=>

"1 "
+
из Сишного мануала по printf()

0 The value should be zero padded. For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, the converted value is padded on the left
with zeros rather than blanks. If the 0 and - flags both appear, the 0 flag is ignored. If a precision is given with a numeric conversion
(d, i, o, u, x, and X), the 0 flag is ignored. For other conversions, the behavior is undefined.

- The converted value is to be left adjusted on the field boundary. (The default is right justification.) Except for n conversions, the con&#8208;
verted value is padded on the right with blanks, rather than on the left with blanks or zeros. A - overrides a 0 if both are given.
 
Сверху