dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB.NET
Expertise: Intermediate
Dec 8, 2004

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Format a Textbox String to the Correct Currency

This code allows you to format a textbox string to the correct currency in SQL Server, independent of regional settings or the user input decimal symbol:

 Public Function FormatMoney(ByVal strValue As String) As String
        '**This function fails if the user uses a digit grouping symbol and no decimal symbol.
        '** Get the decimal symbol from the system
        Dim DecS As String = Mid$(CStr(1.1), 2, 1)
        '** Find the location of the first dot
        Dim intDot As Integer = InStr(strValue, ".")
        '** Find the location of the first comma
        Dim intComma As Integer = InStr(strValue, ",")

        '** Select your regional decimal sign
        Select Case DecS
            Case ","
                '** Check to see if a dot or comma was used by the user
                If intDot > intComma Then
                    '** make sure only the decimal sign remains
                    strValue = Replace(strValue, ",", "")
                    strValue = Replace(strValue, ".", ",")
                End If
                '** round the value to 2 decimals
                strValue = Decimal.Round(strValue, 2)
                '** prepare the value for SQL server
                strValue = Replace(strValue, ",", ".")
            Case "."
                If intComma > intDot Then
                    '** make sure only the decimal sign remains
                    strValue = Replace(strValue, ".", "")
                    strValue = Replace(strValue, ",", ".")
                End If
                '** round the value to 2 decimals
                strValue = Decimal.Round(strValue, 2)
        End Select
        Return strValue
    End Function
Bart Thieme
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date