为缺乏格式的asp经典添加逗号到数字

时间:2014-02-03 07:11:40

标签: asp-classic

  

想要数字= 1234567,数字= 12,34,567格式的asp经典

现在使用格式编号我得到的结果如下

输出:

1234567

我想要类似的东西 12,34,567

1 个答案:

答案 0 :(得分:-2)

这是解决方案

'-------------- currency conversion ----------
Function CurrencyINR(CurStr)
Dim StrCur 
Dim Amount 
Dim LenAmt 
Dim DecPos 
'Convert into Decimal
CurStr=FormatNumber(CurStr)
'Change as String
Amount =Cstr(CurStr)
'Replace the Commas
Amount =Replace(CurStr,",","")
'Seperate the Rupees and Paise
StrCur=Left(Amount,Len(Amount)) 
'Find the Decimal Position
DecPos=Instr(StrCur,".")
'Find the Decimal Values
DecVal= Mid(StrCur,DecPos+1,2)
'Seperate the Rupees
StrCur= Mid(StrCur,1,DecPos-1)
'Find the Length of Amount
LenAmt=Len(StrCur)
'If Decimal Value is Null 
If DecVal="" Then
    DecVal="00"
End If
'Adding the Commas
If LenAmt=1 Then
    StrCur=StrCur &"."& DecVal
ElseIF LenAmt=2 Then
    StrCur=StrCur &"."& DecVal
ElseIF LenAmt=3 Then 
    StrCur=StrCur &"."& DecVal 
ElseIF LenAmt=4 Then
    StrCur=Left(StrCur,1)&","& Right(StrCur,3) &"."& DecVal 
ElseIF LenAmt=5 Then 
    StrCur=Left(StrCur,2)&","& Right(StrCur,3)&"."& DecVal 
ElseIF LenAmt=6 Then
    StrCur=Left(StrCur,1) &","& Mid(StrCur,2,2) & "," & Right(StrCur,3)&"."& DecVal 
ElseIF LenAmt=7 Then 
    StrCur=Left(StrCur,2) &","& Mid(StrCur,3,2) & "," & Right(StrCur,3)&"."& DecVal
ElseIF LenAmt=8 Then 
    StrCur=Left(StrCur,1) &","& Mid(StrCur,2,2) & "," & Mid(StrCur,4,2) & "," & Right(StrCur,3)&"."& DecVal
ElseIF LenAmt=9 Then
    StrCur=Left(StrCur,2) &","& Mid(StrCur,3,2) & "," & Mid(StrCur,5,2) & "," & Right(StrCur,3)&"."& DecVal
end If
CurrencyINR=StrCur
End Function