VAL  
説明

文字列の先頭にある数字を数値に変換します。

 
戻り値

数値。変換に失敗した場合は 0 が返されます。

 
カテゴリ

変換関数、文字列関数

 
関数のシンタックス
Val(string)
 
関連項目

IsNumeric

 
パラメータ

 
使用方法

この関数は、次のように処理を行います。

  • TestValue = "234A56?7'" の場合、Val(TestValue) は 234 を返します。
  • TestValue = "234'5678'9?'" の場合、Val(TestValue) は 234 を返します。
  • TestValue = "BG234" の場合、Val(TestValue) は値 0 を返します (エラーではありません)。
  • TestValue = "0" の場合、Val(TestValue) は値 0 を返します (エラーではありません)。
 
<h3>Val の例</h3>
<cfif IsDefined("FORM.theTestValue")>
   <cfif Val(FORM.theTestValue) is not 0>
      <h3>文字列 <cfoutput>#DE(FORM.theTestValue)#</cfoutput>
 は次の数値に変換できます。
      <cfoutput>#Val(FORM.theTestValue)#</cfoutput></h3>
   <cfelse>
      <h3>文字列 <cfoutput>#DE(FORM.theTestValue)#
       </cfoutput> の先頭は、数値に変換できません。</h3>
   </cfif>
</cfif>
<form action = "val.cfm">
<p>文字列を入力し、数値として評価できるかどうかを調べます。
<p>
<input type = "Text" 
   name = "TheTestValue" 
   value = "123Boy">
<input type = "Submit" 
   value = "数字で始まりますか?" 
   name = "">
</form>
STRING  
文字列、または文字列を含んでいる変数です。