输入字段将十进制数设置为0?

时间:2015-01-02 14:57:00

标签: php

我的页面中有多个输入字段,但其中有两个不记得逗号后面的数字。当我填写34,71并按下保存按钮时,它变为34,0。两个输入字段都会出现这个确切的问题。

2个输入字段的代码:

<tr><td>Btw tarief: </td><td>        <input type="text" name="tarief_btw" id="tarief_btw" value="<? $tarief_btw = $tarief_btw*100; $tarief_btw=number_format($tarief_btw, 1, ',', ''); echo $tarief_btw ?>"></td></tr>
<tr><td>Btw goed doel:</td><td> <input type="text" name="goed_doel_btw" id="goed_doel_btw" value="<? $goede_doel_btw = $goede_doel_btw*100; $goede_doel_btw=number_format($goede_doel_btw,1,',', ''); echo $tarief_btw ?>"></td></tr>

所有代码:

<?php

require_once('inc/head.php');
 ?>
<div id="post-931" class="post-931 page type-page status-publish hentry">


<?php if(isset($_SESSION['hash']) && isset($_SESSION['right_groups']) &&      $_SESSION['right_groups'][1] == null ){
$social_wrapper = new SocialModuleWrapper();

if($_POST)
{
    //applies any updates to the fees, taxes and charity name
    $social_wrapper->updateGroupPost($main_group_id, array(
        'body' => stripslashes($_POST['tarief'])
    ), $tarief_id);
    $social_wrapper->updateGroupPost($main_group_id, array(
        'body' => stripslashes(($_POST['tarief_btw']/100))
    ), $tarief_btw_id);
    $social_wrapper->updateGroupPost($main_group_id, array(
        'body' => stripslashes(($_POST['goed_doel_btw']/100))
    ), $goede_doel_btw_id);
    $social_wrapper->updateGroupPost($main_group_id, array(
        'body' => stripslashes(($_POST['goed_doel']))
    ), $goed_doel_id);

    echo"<h1>Wijzigingen opgeslagen</h1>";
}




//gets the fee, taxes and charity name
$tarief = $social_wrapper->getGroupPost(1,$tarief_id);
$tarief = $tarief['body'];
$tarief_btw = $social_wrapper->getGroupPost(1,$tarief_btw_id);
$tarief_btw = $tarief_btw['body'];
$goede_doel_btw = $social_wrapper->getGroupPost(1,$goede_doel_btw_id);
$goede_doel_btw = $goede_doel_btw['body'];
$goed_doel = $social_wrapper->getGroupPost(1,$goed_doel_id);
$goed_doel = $goed_doel['body'];






        //creates the view to edit fee, taxes and charity name?>

    <div class="entry-content" style="height:300px;">
        <div id="simplr-form">
            <form action="/tarieven.php" method="post">
        <h1>Tarieven</h1>
        <table id="Tarief">

<tr><td>Tarief Commercial Area:</td><td> <input type="text" name="tarief" id="tarief" value="<?=$tarief?>"></td>  </tr>
<tr><td>Btw tarief: </td><td>        <input type="text" name="tarief_btw" id="tarief_btw" value="<? $tarief_btw = $tarief_btw*100; $tarief_btw=number_format($tarief_btw, 1, ',', ''); echo $tarief_btw ?>"></td></tr>
<tr><td>Btw goed doel:</td><td> <input type="text" name="goed_doel_btw" id="goed_doel_btw" value="<? $goede_doel_btw = $goede_doel_btw*100; $goede_doel_btw=number_format($goede_doel_btw,1,',', ''); echo $tarief_btw ?>"></td></tr>
<tr><td>Goede doel van de maand:</td><td> <textarea rows="4" name="goed_doel" id="goed_doel"><?=$goed_doel?></textarea></td></tr>

        </table>
        <input type="submit" name="submit-reg" value="Opslaan" class="submit button">
</form>
    </div></div></div>

    <?
require('inc/footer.php');
}else{
?></div> <?
require('404.php');
}

1 个答案:

答案 0 :(得分:0)

您无法使用欧洲代表表示号码。 PHP并不知道34,71确实是34.71。它将它视为一个字符串,通过它自己的int-&gt;字符串转换规则将其转换为数字,并且您的文本实际上将是:

$foo = $value_from_form / 100;
becomes
$foo = '34,71' / 100;
becomes
$foo = '34' / 100;
becomes
$foo = 34 / 100;

= 0.34

要么修改你的字符串以将34,71转换为34.71 之前你做任何&#34;数学&#34;在该号码上,或者不允许将奇怪的数字表示输入您的字段。