数値、通貨、パーセント項目において、項目定義の「小数点の位置」で設定した桁数を超える値を入力すると、標準動作では自動的に四捨五入されて保存されます。この記事では、入力値が勝手に変更されるのを防ぐために、入力規則の MOD 関数を使用して、指定した桁数を超える入力があった場合にエラーを表示させる設定方法について説明します。
入力規則の数式は、「小数点を右にずらして(乗算して)、それでもまだ小数点が残っている(1 で割った余りが 0 ではない)ならエラー」というロジックを使用します 。
【考え方の例】小数点第 2 位までに制限したい場合
判定のために、数値を 100 倍して小数点を右に 2 つ移動させます。
保存できる場合
入力値: 123.45
右に 2 つずらす(100倍): 12345
小数点は残っていないため、保存される。
エラーになる場合
入力値: 123.456
右に 2 つずらす(100倍): 12345.6
「.6」という端数が残っているため、入力規則によりエラーとなる。
実際には以下のような数式を設定します。
MOD( FieldName__c * 100, 1 ) <> 0
MOD( FieldName__c * 10000, 1 ) <> 0
※ FieldName__c はパーセント項目の API 参照名に置き換えてください。005132292

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.