-
Jul 1st, 2011, 06:43 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Scientific notation to string
How do I get a huge value (more than 16 digits from double var) into a textbox without it being in scientific notation.
Val() and CDbl() returns a value like 1.0923772290313E+15 but I need the number without it being in the E+15 format e.g. 109237722903135248725245
-
Jul 1st, 2011, 07:39 AM
#2
Re: Scientific notation to string
Try something like this
Code:
txtBox.Text = Format(dblValue,"#0.00")
Where dblValue is your double variable
-
Jul 1st, 2011, 10:29 AM
#3
Re: Scientific notation to string
however it returns only 15 digits after that only zeros.
-
Jul 1st, 2011, 10:32 AM
#4
Thread Starter
Hyperactive Member
Re: Scientific notation to string
So how do I get my formula to return more than 15 digits?
-
Jul 1st, 2011, 10:43 AM
#5
Re: Scientific notation to string
Text1.Text = Mid(Format$(dblValue, "0"), 1, 15)
-
Jul 1st, 2011, 10:46 AM
#6
Re: Scientific notation to string
this may be useful
Code:
Dim i As Long
Dim x
x = 1
For i = 1 To 74
x = CDec(x * 2)
Next
MsgBox x
-
Jul 1st, 2011, 10:48 AM
#7
Re: Scientific notation to string
Originally Posted by Bezzie
So how do I get my formula to return more than 15 digits?
You can use the CDec() function. Try this:
Code:
Debug.Print "Single: "; CSng(1/3)
Debug.Print "Double: "; CDbl(1/3)
Debug.Print "Decimal #1: "; CDec(1/3)
Debug.Print "Decimal #2: "; CDec(1) / CDec(3) ' CDec( 1 / CDec(3)) returns same result
' note that to gain max digits, internal parts of calc need to be converted to decimal
Results look like this:
Single: 0.3333333
Double: 0.333333333333333
Decimal #1: 0.333333333333333
Decimal #2: 0.3333333333333333333333333333
Last but not least. To store the result in a variable, use Variant, not Double, not Long:
Code:
Dim vDec As Variant
vDec = CDec(1) / CDec(3)
Edited: seenu_1st beat me to it.
Last edited by LaVolpe; Jul 1st, 2011 at 11:04 AM.
-
Jul 1st, 2011, 11:06 AM
#8
Thread Starter
Hyperactive Member
Re: Scientific notation to string
The number is a whole number, not a decimal number.
-
Jul 1st, 2011, 11:10 AM
#9
Re: Scientific notation to string
Doesn't matter, logic is the same. Look at the post by seenu_1st for whole number example.
How many digits are you going to need. Even the CDec() has limits.
Edited: Here's the max limits per MSDN
Originally Posted by MSDN
+/-79,228,162,514,264,337,593,543,950,335 for zero-scaled numbers, that is, numbers with no decimal places.
For numbers with 28 decimal places, the range is +/-7.9228162514264337593543950335.
The smallest possible non-zero number is 0.0000000000000000000000000001 (+/-1E-28).
Last edited by LaVolpe; Jul 1st, 2011 at 11:14 AM.
-
Jul 1st, 2011, 12:29 PM
#10
Thread Starter
Hyperactive Member
Re: Scientific notation to string
I need 16 digits at the moment but not more than 20.
Thanks guys. I'm going to look into the suggestions.
-
Jul 1st, 2011, 01:42 PM
#11
Re: Scientific notation to string
In my post #5 you can change the '15' to 16 or 20 to get that number of digits.
-
Jul 1st, 2011, 01:57 PM
#12
Re: Scientific notation to string
So this thread is not about either scientific notation or strings it seems. The question appears to really be about expressions with more precision than Double arithmetic offers.
-
Jul 1st, 2011, 03:26 PM
#13
Thread Starter
Hyperactive Member
Re: Scientific notation to string
My problem was when I did the arithmetic the Val() and CDbl() functions returned the value in scientific notation. I needed to know how to get it in whole number and not scientific notation.
-
Jul 1st, 2011, 04:12 PM
#14
Re: [RESOLVED] Scientific notation to string
Well you're still doomed using Double then.
Data Type Summary
So anyway, you can use things like:
Code:
Dim A, B
A = CDec("79228162514264337593543950335")
B = A - 1
MsgBox Format$(B, "#0")
But to ensure Decimal arithmetic you'll want to leave out any doubts, as in:
Code:
Dim A, B
A = CDec("79228162514264337593543950335")
B = A - CDec(1)
MsgBox Format$(B, "#0")
-
Jul 3rd, 2011, 02:09 AM
#15
Thread Starter
Hyperactive Member
Re: [RESOLVED] Scientific notation to string
The Dec part of the CDec() confused me. I thought it's a function for Decimals. Should get it working though.
What is the proper type of variable I should use if Double is going to give problems. I changed it to Variant as suggested by LaVolpe.
-
Jul 3rd, 2011, 06:02 AM
#16
Re: [RESOLVED] Scientific notation to string
Strictly speaking a decimal number is any number represented in base 10, regardless of how many decimal places it has. If you require 20 significant figures it is the only type available in VB6 that can hold that many. Decimal is not a type in its own right, rather a subtype of Variant.
Your only other option is to spread your large number over several variables which is fairly complicated.
-
Jul 3rd, 2011, 10:05 AM
#17
Thread Starter
Hyperactive Member
Re: [RESOLVED] Scientific notation to string
Thanks guys. Got it working with Variant and CDec(). English is second language for me so didn't understand it correctly. To me decimals means the digits after the point.
-
Jul 30th, 2014, 02:31 PM
#18
Re: [RESOLVED] Scientific notation to string
And just to be clear: the Decimal subtype of the Variant type does not contain "base 10" values at all.
Decimal variables are stored as 96-bit (12-byte) unsigned integers scaled by a variable power of 10. The power of 10 scaling factor specifies the number of digits to the right of the decimal point, and ranges from 0 to 28.
-
Jul 30th, 2014, 10:26 PM
#19
Re: [RESOLVED] Scientific notation to string
@dilettante: Did you mean to get the spade out ?
-
Jul 30th, 2014, 10:40 PM
#20
Re: [RESOLVED] Scientific notation to string
Originally Posted by dilettante
And just to
I am impressed that you managed to remember that three years after the fact.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Aug 28th, 2017, 08:13 AM
#21
Re: [RESOLVED] Scientific notation to string
Originally Posted by Bezzie
English is second language for me so didn't understand it correctly. To me decimals means the digits after the point.
Hi Bezzie,
A quick English language lesson.xoxoxoxoxoxoxoxoxoxoxoxo
You're not far out... 'decimals' refers as stated, to the 'base 10'.
'Decimal Places' is the expression for 'digits after the point'.
And 'the point' should actually be 'the decimal point'.
Here endeth the lesson.
Poppa.
Along with the sunshine there has to be a little rain sometime.
-
Aug 28th, 2017, 08:27 AM
#22
Re: [RESOLVED] Scientific notation to string
pop...
Bezzie hasn't been on this thread for over six years (July 2011)...do you REALLY think OP will read what you wrote?
-
Aug 28th, 2017, 09:35 AM
#23
Thread Starter
Hyperactive Member
Re: [RESOLVED] Scientific notation to string
Actually did read it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|