さまざまな変数の文字列を一緒に作成する必要があり、先頭にゼロを埋め込む必要があります。また、小数点以下の値がゼロの場合は小数点を保持する必要があります。変数が単なるゼロの場合、それを完全に抑制してスペースで埋めたい
例えば:
変数で 0 を取得し、サイズが 3 の場合、文字列を次のようにしたい: " " 変数で 9 を取得し、サイズが 3 の場合、変数で 90.0 を取得し、それがサイズが 10 の場合、必要な文字列: "00000090.0"
私は使用しようとしています:
public function PadField(byval field as object, byval size as int16) as string
dim fieldstring as string = string.empty
dim fieldDate as date
' here I want to check for a numeric variable
if isnumeric(field) then
' if the variable is an integer with a value of zero...
if cint(field) = 0 then
stringField = string.empty.padleft(size,"0")
' else if the variable is an integer greater than zero...
elseif cint(field) > 0 then
stringField = field.toString.padLeft(size,"0")
End If
' else if a date, I want date to look like MM/dd/yyyy...
elseif IsDate(field) then
fieldDate = field
strigField = fieldDate.ToString("MM/dd/yyyy")
' else if a string, then I want to pad after with spaces
else
stringField = field.ToString.Trim.toUpper.PadRight(size," ")
End If
return stringField
end Function
問題は、1234.0 のような変数を渡すと、次の結果が得られることです。
"0001234"
でも私はしたい:
"0001234.0"
1234.1 を送信すると動作し、1 を送信すると「0001234.1」が返され、90 を送信すると「001」が取得され、日付を送信すると「090」が取得されます。 「08/21/2012」を取得するには、文字列を送信すると、「NAME」を取得したい
小数がゼロのときに小数を保持する方法について誰か助けてもらえますか?