Re: Number formats problems



You're heading for heaps of trouble here. Why are you putting your number in
a String instead of

dim a as double
a = 120.34

This is part of your problem. You're putting a UK/US format number into a
string, and this is causing FormatNumber to try and convert it to a proper
number before it performs the required formatting. It would seem that you're
currently in a locale where "." is the triple character and so that "120.34"
is actually being interpreted as 12,034.00.

If you'd specified the number directly, as shown above, then the
interpretation is unambiguous. VB literals *always* use "." as the decimal
separator, otherwise VB source code would not be portable.

If you want to format the final string representation of your number with a
triple character that isn't the one in the active regional settings (which
doesn't seem a good idea) then you would have to do it manually.
FormatNumber will always acknowledge the user's regional settings

Tony Proctor

"Prashwee" <prashantha.weerakoon@xxxxxx> wrote in message
news:OzqQ2DC4FHA.1188@xxxxxxxxxxxxxxxxxxxxxxx
> hello All
> I have a very simple question but bit confusing
>
> First of all i changed my reginal settings to swedish.
>
> Then i run the simple code below
>
> dim a as String
> a="120.34"
>
> FormatNumber(a, , vbFalse, vbFalse, vbTrue) returns me with 12 234
> I know that "." is for thusand separtor in swdish settings but i am
> expecting a result of 120,34
> how can i achive it?
> The solution should be compatible with any regional setting
>
> Please help me
> Thanks in advance
> /PRash
>
>


.



Relevant Pages

  • Re: parse cell contents
    ... extract the date I will get the yyyy-mm-dd format. ... What we will do is first look at the first word in the string. ... Dim ValidEntry As Boolean ... 'Set the pattern by using the Pattern property. ...
    (microsoft.public.excel.programming)
  • Re: Setting field properties in code
    ... format that the user has defined in the Windows Control Panel, ... >> Sub StandardProperties(strTableName As String) ... >> Dim tdf As DAO.TableDef 'Table nominated in argument. ... >> Dim ind As DAO.Index ...
    (comp.databases.ms-access)
  • Re: Zellformatierung vQ=B6llig_selbstherrlich_=2897=29?=
    ... indem Du das Format selbst exakt defninierst. ... >> Public Sub Sammeln(Name As String) ... >> Dim EingangAs String ... Eine Alternative ist auch der Makro-Recorder während Du eine Zelle als Text ...
    (microsoft.public.de.excel)
  • Re: tab in userform locks program
    ... > I am a VBA newbie and have not been using DIM in my code so it is ... declare a variable at the top of a standard module using Private (module ... You may notice that I used Format$ instead of Format. ... but Format$ returns a String whereas ...
    (microsoft.public.excel.programming)
  • Re: Spellnumber - USD/AFa
    ... >>> format it returns me Afghani which is correct and also when I change ... >> Public Function DollarsAFAAs String ... >> Dim DecimalPoint As Long ... >> Dim TestValue As Long ...
    (microsoft.public.excel.misc)