none
How to Evaluate Local Formatted Number and Currency Correctly in VB.NET RRS feed

  • 问题

  • Recently, when we develop different links modules for QwikQuote (http://www.qwikquote.com) to different contact, CRM, and accounting software solutions, we encounter a problem that VB.NET Double.Parse() and Decimal.Parse()function does not return the correctly formatted number and currency in none English language Windows OS where their decimal point is not a dot (‘.’) but (‘,’).  Does anybody encounter this problem and know how to resolve this issue.  This problem also exist in VB 6.0 CDbl() and CCur()
    2011年3月5日 3:22

答案

  • Hi,

    In this case I would suggest you to use String.Format to represent you value in correct number format.

    e.g.

     

     

     Thread.CurrentThread.CurrentCulture = _

             New CultureInfo("sl-SI")

            Dim a As Decimal = 12.356

            MsgBox(String.Format("{0:n}", a))

     

            Thread.CurrentThread.CurrentCulture = _

            New CultureInfo("zh-hk")

            MsgBox(String.Format("{0:n}", a))

    It should display the value with the correct decimal symbol.

     

    Please correct me if my concept is wrong



    Chi
    2011年3月5日 4:12
    版主

全部回复

  • Recently, when we develop different links modules for QwikQuote (http://www.qwikquote.com) to different contact, CRM, and accounting software solutions, we encounter a problem that VB CDbl() and CCur() function does not return the correctly formatted number and currency in none English language Windows OS where their decimal point is not a dot (‘.’) but (‘,’).  Does anybody encounter this problem and know how to resolve this issue.
    2011年3月5日 2:32
  • Hi,

    In this case I would suggest you to use String.Format to represent you value in correct number format.

    e.g.

     Thread.CurrentThread.CurrentCulture = _

             New CultureInfo("sl-SI")

            Dim a As Decimal = 12.356

            MsgBox(String.Format("{0:n}", a))

     

            Thread.CurrentThread.CurrentCulture = _

            New CultureInfo("zh-hk")

            MsgBox(String.Format("{0:n}", a))

    It should display the value with the correct decimal symbol.

    Please correct me if my concept is wrong


    Chi
    2011年3月5日 3:40
    版主
  • Hi,

    In this case I would suggest you to use String.Format to represent you value in correct number format.

    e.g.

     

     

     Thread.CurrentThread.CurrentCulture = _

             New CultureInfo("sl-SI")

            Dim a As Decimal = 12.356

            MsgBox(String.Format("{0:n}", a))

     

            Thread.CurrentThread.CurrentCulture = _

            New CultureInfo("zh-hk")

            MsgBox(String.Format("{0:n}", a))

    It should display the value with the correct decimal symbol.

     

    Please correct me if my concept is wrong



    Chi
    2011年3月5日 4:12
    版主