如何在javascript中显示十进制后的两位数

时间:2018-03-07 07:07:42

标签: javascript html angularjs jsp

我正在使用$newObj = new AdCreative(null, 'act_account_id'); $newData = []; $fields = [ AdCreativeFields::NAME, AdCreativeFields::TITLE, AdCreativeFields::BODY, AdCreativeFields::OBJECT_URL, AdCreativeFields::LINK_URL, AdCreativeFields::IMAGE_HASH, AdCreativeFields::OBJECT_STORY_ID, AdCreativeFields::OBJECT_STORY_SPEC, AdCreativeFields::URL_TAGS, ]; foreach ($fields as $field) { $value = $oldAdCreative->{$field}; if(isset($newValues[$field])){ $value = $newValues[$field]; } $newData[$field] = $value; } $newObj->setData($newData); $newObj->create(); // Assigning New Creative ID to Ad $ad = new Ad($adId); $ad->update(array( 'creative' => ['creative_id' => $newObj->{AdCreativeFields::ID}], 'redownload' => true, )); 进行观看。我正在使用JSPangularjs

我有一个文本框,在该文本框中有一个名为javascript的值。 12.542001应该包含相同内容,但在我显示时,我只想在文本框中显示ng-model

如果我使用12.54,那么它会对值进行舍入,但我不想舍入该值...

1 个答案:

答案 0 :(得分:1)

试试这个



console.log(parseFloat(Math.round(12.542001 * 100) / 100).toFixed(2));

//or use 

num = "122.542001";
var spV= num.split(".");
console.log(spV[0] +"."+ spV[1].substring(0,2));




更新

如果您的ng型号名称为$scope.totalnumber。然后尝试这个

$scope.totalnumber = parseFloat(Math.round($scope.totalnumber * 100) / 100).toFixed(2)