You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ng2-currency-mask输入默认从分位开始,如何改为从元位输入?

ng2-currency-mask: Starting Input from Integer Place Instead of Decimal

Hey there! Let me clarify this for you:

Is this intended design or a configuration mistake?

This is actually the default intended behavior of the ng2-currency-mask component. By default, it uses a "mask input mode" that mimics traditional cash register behavior—where you start typing from the smallest decimal place (cents) first. So typing 33 gets interpreted as 33 cents, hence showing up as $.33.

Can you adjust it to start from the integer place (dollars)?

Absolutely! You can modify this behavior by tweaking the component's inputMode configuration. Here's how to do it:

  • In your template where you're using the currency mask, add the inputMode property and set it to 'text':
    <input type="text" currencyMask [inputMode]="'text'" [options]="{ prefix: '$', decimal: '.', thousands: ',' }" />
    
  • Ensure your options object is configured to match your desired currency format (like setting the correct prefix, decimal separator, etc.).

With inputMode="text", the component will behave like a standard text input field—typing 33 will now render as $33.00 instead of $.33.

A quick double-check: Make sure you don't have any conflicting options enabled (like allowZeroDecimal set to false, though this is unlikely to cause this specific issue).

That should adjust the input flow to start from the integer place exactly as you want!

内容的提问来源于stack exchange,提问作者Chris Westbrook

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:17:02