[英]How to use PHP's sprintf with type specifier %u in C#
I've searched on StackOverflow and found that PHP's sprintf
in C# is String.Format
. 我搜索了StackOverflow,发现C#中PHP的
sprintf
是String.Format
。
In sprintf
when the type specifier is u
, it means the argument is treated as an integer, and presented as an unsigned decimal number. 在
sprintf
,类型说明符为u
,表示参数被视为整数,并以无符号十进制数形式出现。
How do I convert the PHP function sprintf
with type specifier %u
to C#? 如何将类型说明符为
%u
的PHP函数sprintf
转换为C#?
All help is sincerely appreciated. 衷心感谢所有帮助。
Code 码
var myInt = -13458;
if(myint >= 0)
Console.Print(String.Format("This is value threated as %u: {0}", myInt));
else
Console.Print(String.Format("This is value threated as %u: {0}", -1 * myInt));
Reason: 原因:
1) An optional sign specifier that forces a sign (- or +) to be used on a number.
1)可选的符号说明符,用于强制在数字上使用符号(-或+)。 By default, only the - sign is used on a number if it's negative.
默认情况下,如果数字为负,则仅对数字使用-号。 PHP: sprintf
PHP的:sprintf
Simply multiply it with (-1)
when input value is less than zero 当输入值小于零时,只需将其乘以
(-1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.