Decimal symbol: Comma or decimal point


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 12 of 12

Thread: Decimal symbol: Comma or decimal point

  1. #1
    Ingo Guest

    Decimal symbol: Comma or decimal point

    I would like to retrieve which decimal symbol my international user is
    using (comma, point, ...): how can I do that?

    Thanks for replying.





    Ciao,
    Giovanni (e-mail: buomminoX@Ycsi.com)

    --------------------------------------------------------------------
    WARNING! To email me, remove X and Y from my address.
    --------------------------------------------------------------------

  2. #2
    Karl E. Peterson Guest

    Re: Decimal symbol: Comma or decimal point

    Hi Giovanni --

    >I would like to retrieve which decimal symbol my international user is
    >using (comma, point, ...): how can I do that?


    Here's a simple way: Mid$(Format(1.2, "0.0"), 2, 1)

    Later... Karl




  3. #3
    Craig Clearman Guest

    Re: Decimal symbol: Comma or decimal point

    Buon giorno Giovanni,

    >I would like to retrieve which decimal symbol my international user is
    >using (comma, point, ...): how can I do that?


    GetLocaleInfo() will get the information:

    Private Const LOCALE_SDECIMAL As Long = &HE& ' decimal
    separator
    Private Const LOCALE_STHOUSAND As Long = &HF& ' thousand
    separator

    Private Const LOCALE_SMONDECIMALSEP As Long = &H16& ' monetary
    decimal separator
    Private Const LOCALE_SMONTHOUSANDSEP As Long = &H17& ' monetary
    thousand separator

    Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As
    Long
    Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long

    Private Declare Function GetLocaleInfo _
    Lib "kernel32" Alias "GetLocaleInfoA" ( _
    ByVal Locale As Long, _
    ByVal LCType As Long, _
    ByVal lpLCData As String, _
    ByVal cchData As Long) As Long

    Private Sub Form_Load()

    Dim h As Long
    Dim sData As String
    Dim hLocale As Long

    hLocale = GetUserDefaultLCID()
    If hLocale Then
    sData = Space$(255)
    h = GetLocaleInfo(hLocale, LOCALE_SDECIMAL, sData, Len(sData))
    If h Then
    sData = Mid$(sData, h - 1)
    Debug.Print sData
    End If
    End If

    End Sub

    Ciao, Craig


  4. #4
    Craig Clearman Guest

    Re: Decimal symbol: Comma or decimal point

    Hi Karl,

    >Here's a simple way: Mid$(Format(1.2, "0.0"), 2, 1)


    D'oh! It can't be that easy!

    Okay. Maybe it can.

    It looks like VB will translate commas in format statements to the
    user defined thousand separator, decimal points to the user defined
    decimal separator and slashes to the user defined date separator.

    Me.Print Format$(1000.2, "#,###.0")
    Me.Print Format$(Now, "MM/DD/YYYY")

    I'd seen the slash change in the past, but I had no idea it would do
    the same for decimals and commas.

    Do you know of any other (non-named) changes?

    Ciao, Craig


  5. #5
    Audie F. Thomas Guest

    Re: Decimal symbol: Comma or decimal point

    > I would like to retrieve which decimal symbol my international user is
    > using (comma, point, ...): how can I do that?


    I have not tried this but, you might try something like this:

    Warning: Air Code

    Dim sDecimal As String
    sDecimal = Mid$(Format(1.1, "0.0))








  6. #6
    Karl E. Peterson Guest

    Re: Decimal symbol: Comma or decimal point

    Hi Craig --

    >>Here's a simple way: Mid$(Format(1.2, "0.0"), 2, 1)

    >
    >D'oh! It can't be that easy!
    >
    >Okay. Maybe it can.


    <chuckle>

    >It looks like VB will translate commas in format statements to the
    >user defined thousand separator, decimal points to the user defined
    >decimal separator and slashes to the user defined date separator.
    >
    >Me.Print Format$(1000.2, "#,###.0")
    >Me.Print Format$(Now, "MM/DD/YYYY")
    >
    >I'd seen the slash change in the past, but I had no idea it would do
    >the same for decimals and commas.
    >
    >Do you know of any other (non-named) changes?


    I think you can get the currency symbol this way, too.

    Later... Karl




  7. #7
    Craig Clearman Guest

    Re: Decimal symbol: Comma or decimal point

    Craig,

    > sData = Mid$(sData, h - 1)


    Left$(), silly.

    Ciao, Craig


  8. #8
    Craig Clearman Guest

    Re: Decimal symbol: Comma or decimal point

    Hi Karl,

    >>Do you know of any other (non-named) changes?

    >
    >I think you can get the currency symbol this way, too.


    Doesn't appear to, here.

    Ciao, Craig


  9. #9
    Audie F. Thomas Guest

    Re: Decimal symbol: Comma or decimal point

    Air code has an error. Just look at Karl's example instead.



  10. #10
    Rick Rothstein Guest

    Re: Decimal symbol: Comma or decimal point

    The Currency symbol is not as straight forward as the decimal or date
    separators (As it turns out, the "thousand" separator might also be
    problematici -- see below). It can appear at the beginning or the end of a
    displayed number and I think it can be more than one character long. Hence,
    a routine is needed to avoid the API call. This appears to work:

    Number = Format$(0, "currency")
    If Left$(Number, 1) <> "0" Then
    Index = 1
    Do While Mid$(Number, Index, 1) <> "0"
    CurrencySymbol = CurrencySymbol & Mid$(Number, Index, 1)
    Index = Index + 1
    Loop
    Else
    Index = Len(Number)
    Do While Mid$(Number, Index, 1) <> "0"
    CurrencySymbol = Mid$(Number, Index, 1) & CurrencySymbol
    Index = Index - 1
    Loop
    End If
    CurrencySymbol = Trim$(CurrencySymbol )

    As for the ThousandsSeparator . . . although I couldn't get VB to respect my
    Regional settings for the this when I changed it, the Regional settings
    provide for a different amount of characters in the "digital grouping"
    between what I called the "thousands" separator. It *might* be more
    appropriate to get this symbol using:

    Index = 1
    Number = Format$(1000000000, "#,###")
    Do While Mid$(Number, Index, 1) Like "[0-9]"
    Index = Index + 1
    Loop
    ThousandsSeparator = Mid$(Number, Index, 1)

    As for the other two Regional settings, this is my take on them:

    DecimalSeparator = Format$(0, ".")

    and

    DateSeparator = Format$(0, "/")

    Rick


    Karl E. Peterson <karl@mvps.org> wrote in message
    news:38cd48fd@news.devx.com...
    > Hi Craig --
    >
    > >>Here's a simple way: Mid$(Format(1.2, "0.0"), 2, 1)

    > >
    > >D'oh! It can't be that easy!
    > >
    > >Okay. Maybe it can.

    >
    > <chuckle>
    >
    > >It looks like VB will translate commas in format statements to the
    > >user defined thousand separator, decimal points to the user defined
    > >decimal separator and slashes to the user defined date separator.
    > >
    > >Me.Print Format$(1000.2, "#,###.0")
    > >Me.Print Format$(Now, "MM/DD/YYYY")
    > >
    > >I'd seen the slash change in the past, but I had no idea it would do
    > >the same for decimals and commas.
    > >
    > >Do you know of any other (non-named) changes?

    >
    > I think you can get the currency symbol this way, too.
    >
    > Later... Karl
    >
    >
    >




  11. #11
    Ingo Guest

    Re: Decimal symbol: Comma or decimal point

    Thank you to everybody!
    I found the best way to do it was the GetLocaleInfo()

    Ciao,
    Giovanni


    On Mon, 13 Mar 2000 09:39:25 +0100, Ingo <Ingo@SoftHome.net> wrote:

    >I would like to retrieve which decimal symbol my international user is
    >using (comma, point, ...): how can I do that?
    >
    >Thanks for replying.



  12. #12
    Tim Manos Guest

    Re: Decimal symbol: Comma or decimal point

    It might be crude but here's what I use:

    Public Function GetDecPoint() As String
    GetDecPoint = Format$(0, "#.#")
    End Function

    Tim

    Ingo <Ingo@SoftHome.net> wrote in message
    news:l4prcsc72g9qkmjpj86pqluqbf04vot8t2@4ax.com...
    > Thank you to everybody!
    > I found the best way to do it was the GetLocaleInfo()
    >
    > Ciao,
    > Giovanni
    >
    >
    > On Mon, 13 Mar 2000 09:39:25 +0100, Ingo <Ingo@SoftHome.net> wrote:
    >
    > >I would like to retrieve which decimal symbol my international user is
    > >using (comma, point, ...): how can I do that?
    > >
    > >Thanks for replying.

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center