Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
Intermediate
Date of registration: Jan 1st 2009
Location: Hanover, Germany
Occupation: Software Engineer
Hobbies: Hilbert Curves
Jabaco Source |
|
1 2 3 4 5 |
Option Explicit Public Function Val(expression As String) Val = CDbl(expression) End Function |
Intermediate
Date of registration: Jan 1st 2009
Location: Hanover, Germany
Occupation: Software Engineer
Hobbies: Hilbert Curves
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Option Explicit Public Sub Command1_Click() t "1,234" t "1.234" t "1,234.56" End Sub Private Sub t(s As String) Dim a As New VBVariant(s) Dim x As Double = a.doubleValue() Debug.Print s & " = " & x End Sub |
Source code |
|
1 2 3 4 |
... 1,234 = 0.0 1.234 = 1.234 1,234.56 = 0.0 |
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
Public Sub Form_Load() cdblWert CDbl("123,04") ' VB = 123,04 / JB = 0.0 cdblWert CDbl(123.04) ' VB = 123,04 / JB = 123.04 cdblWert CDbl("123.04") ' VB = 12304 / JB = 123.04 cintWert CInt("123,04") ' VB = 123 / JB = 0 cintWert CInt(123.6) ' VB = 124 / JB = 124 cintWert CInt("123.04") ' VB = 12304 / JB = 123 clngWert CLng("123,04") ' VB = 123 / JB = 0 clngWert CLng(123.6) ' VB = 124 / JB = 124 clngWert CLng("123.04") ' VB = 12304 / JB = 123 valWert Val("123") ' VB = 123 / JB = 123.0 valWert Val("123,04") ' VB = 123 / JB = 0.0 valWert Val("123.04") ' VB = 123,04 / JB = 0.0 valWert Val(" 123 04") ' VB = 12304 / JB = 12304.0 valWert Val("123four") ' VB = 123 / JB = 123.0 valWert Val("one234") ' VB = 0 / JB = 234.0 End Sub Private Sub cdblWert(s As String) Debug.Print s End Sub Private Sub cintWert(s As String) Debug.Print s End Sub Private Sub clngWert(s As String) Debug.Print s End Sub Private Sub valWert(s As String) Debug.Print s End Sub |
Source code |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
/** * Returns the numbers contained in a string as a numeric value of appropriate type. * @author Manuel Siekmann * @param Any valid numeric expression. */ public static double Val(String Expression) { if (Expression == null) { return 0.0; } StringBuffer strBuff = new StringBuffer(); char decimalSeparator = (new java.text.DecimalFormatSymbols()).getDecimalSeparator(); char c; boolean bSetOperator = false; boolean bSetDecimalSeparator = false; for (int i = 0; i < Expression.length() ; i++) { c = Expression.charAt(i); if (Character.isDigit(c)) { strBuff.append(c); } else if (c == '-') { if (bSetOperator == false) { bSetOperator = true; strBuff.append("-"); } } else if (c == '.' || c == ',') { if (bSetDecimalSeparator == false) { bSetDecimalSeparator = true; strBuff.append(decimalSeparator); } } } return (CDbl(new VBVariant(strBuff.toString()))); } |
Jabaco Source |
|
1 2 3 4 5 |
cdblWert CDbl("123,04") ' VB = 123,04 cdblWert CDbl("123.04") ' VB = 12304 cintWert CInt("123,04") ' VB = 123 cintWert CInt("123.04") ' VB = 12304 |
Jabaco Source |
|
1 2 3 4 5 |
cdblWert CDbl("123,04") ' VB = 12304 cdblWert CDbl("123.04") ' VB = 123.04 cintWert CInt("123,04") ' VB = 12304 cintWert CInt("123.04") ' VB = 123 |
Jabaco Source |
|
1 2 3 |
public static double CDbl(VBVariant Expression) { return (Expression.doubleValue()); } |
Jabaco Source |
|
1 2 3 |
public static double CDbl(VBVariant Expression) { return (Expression.replace(',', '.').doubleValue()); } |
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
Public Sub Form_Load() cdblWert CDbl(ul("123,04")) ' VB = 123,04 / JB = 123.04 cdblWert CDbl(123.04) ' VB = 123,04 / JB = 123.04 cdblWert CDbl(ul("123.04")) ' VB = 12304 / JB = 123.04 cintWert CInt(ul("123,04")) ' VB = 123 / JB = 123 cintWert CInt(123.6) ' VB = 124 / JB = 124 cintWert CInt(ul("123.04")) ' VB = 12304 / JB = 123 clngWert CLng(ul("123,04")) ' VB = 123 / JB = 123 clngWert CLng(123.6) ' VB = 124 / JB = 124 clngWert CLng(ul("123.04")) ' VB = 12304 / JB = 123 valWert Val(ul("123")) ' VB = 123 / JB = 123.0 valWert Val(ul("123,04")) ' VB = 123 / JB = 0.0 valWert Val(ul("123.04")) ' VB = 123,04 / JB = 0.0 valWert Val(ul(" 123 04")) ' VB = 12304 / JB = 12304.0 valWert Val(ul("123four")) ' VB = 123 / JB = 123.0 valWert Val(ul("one234")) ' VB = 0 / JB = 234.0 End Sub Private Sub cdblWert(s As String) Debug.Print s End Sub Private Sub cintWert(s As String) Debug.Print s End Sub Private Sub clngWert(s As String) Debug.Print s End Sub Private Sub valWert(s As String) Debug.Print s End Sub Private Function ul(s As String) As String ' ul = unlocalize ul = Replace(s, ",", ".") End Function |
Quoted
I don't think, that such an localization makes sense.
Jabaco Source |
|
1 |
CDbl("123.04") ' VB = 12304 / JB = 123.04 |
Jabaco Source |
|
1 |
Val("123.04") ' VB = 123,04 / JB = 0.0 |
Jabaco Source |
|
1 |
CDbl(123.04) ' VB = 123,04 / JB = 123.04 |
Jabaco Source |
|
1 2 |
Val("one234") ' VB = 0 / JB = 234.0 Val("123 banana 4 free 5") 'VB = 123 / JB = 12345.0 |