English 中文(简体)
PHP(印本、印本)中轮浮式
原标题:Wrong float formatting in PHP (sprintf, printf)

我正在拼凑PHP代码,发现:

$a = 111749392891;

printf( %f , $a);
111749392890.:00000

printf( %F , $a);
111749392890.:00000

printf( %F.2 , $a)
111749392890.:00000.2

printf( %F0.2 , $a);
111749392890.:000000.2

number_format($a, 2,  . ,  );
111749392891.00

只有数字——原产值——对我来说是科索沃。 我失踪了吗? I m使用PHP5.3。

问题回答

您将格式类型变幻剂放在形式类型谱而不是之前。 为此:

printf( %.2F , $a)

至于奇数产出,你的地方化环境是有可能做到的。 跟踪如下线,看你们的当地情况。

echo setlocale(LC_ALL, null);

想把你的地方改变为不同的地方,看问题是否消失。 与此类似:

setlocale(LC_ALL,  en_CA.UTF-8 );




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签