Re: Parsing a string format

Tech-Archive recommends: Fix windows errors by optimizing your registry



Oops, I overcomplicated things a bit there, just use the Val command

Val("+5.15109444E-001") = 0.515109444
Val("+5.34925965E+000") = 5.34925965
Val("+4.87351543E+001") = 48.7351543

Then use Round to limit the number of decimal places. eg:
Round(Val("+4.87351543E+001"), 2)
= 48.74

Personally, I think CDbl would be better to use than Val.

No, if it is a US or UK device working in a machine set with a French
Locale then it will not work at all

If I understand your objection correctly, then I should clarify my response
a little. I assumed that Dave suggested Val because it works with the
numbers that the OP posted. Those numbers, of course, where generated in a
locale where the dot is used for the decimal point. In this case, either Val
or CDbl would work. However, if the numbers are being generated in a locale
where the comma is used as the decimal point, then Val would not work as
Dave had intended (the comma would be the first non-numeric character and
Val would stop at it) because the Val function in not regionally aware; but
CDbl, being regionally aware, would work. If someone from another country is
generating the numbers (comma for the decimal point), the use of CDbl would
need to be used. This international numeric stuff is always a pain to work
with because you have to know if the numbers are generated and processed
within the same regionally set-up computer; otherwise mismatch situations
like you suggest can result.

Rick


.



Relevant Pages

  • Re: Decimal commas instead of decimal points
    ... Don't mix the locale-aware functions (CStr, CDbl, etc) with the ... with CSng or CDbl) then it automatically expect the correct decimal-point ... These alternatives to CStr and CDbl ... the only two VB functions that don't honour the current locale. ...
    (comp.lang.basic.visual.misc)
  • Re: Parsing a string format
    ... Then use Round to limit the number of decimal places. ... I think CDbl would be better to use than Val. ... Locale then it will not work at all ... If I understand your objection correctly, then I should clarify my response ...
    (microsoft.public.vb.winapi)
  • Re: Problem with locale
    ... If you use your app in Germany, you should have German locale and CDbl ...
    (microsoft.public.vb.syntax)
  • Re: Newbie help on String conversion needed please
    ... but will honour both the 'triple separator' and the decimal ... separator used in the current locale. ... Both Valand CDbl() accept E-format numbers ... > Dim SFee as Long ...
    (microsoft.public.vb.general.discussion)
  • Problem with locale
    ... convert it to a double using CDbl. ... non-english locale. ... decimal separator and as a group separator, ... manipulating the string?) ...
    (microsoft.public.vb.syntax)