Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Saving numerical data to text file

Author
Message
-majic-
7
Years of Service
User Offline
Joined: 8th May 2016
Location: 3rd rock from the Sun
Posted: 22nd Nov 2016 01:51
Total brain fart I guess, but I have not been able to come up with the correct code.
I have these numerical data 50.00 , 25.36 , 00.25 , 68.14 and I want to save this data to a text file so that in this text file the numbers are written as 50.00 , 25.36 , 00.25 , 68.14
they would each be on separate line in the text file and look like this:

50.00
25.36
00.25
68.14

but no matter how I define my numbers - real , integer, float, etc. the output to the text file is either gibberish all on one line or very long numbers on different lines as

50.000012305
25.362345999
.25156824693
68.145980356

nothing I do produces my desired results

50.00
25.36
00.25
68.14

Can someone please let me know what I am doing wrong ???
What I have going now is a database using Excel containing numerical data from my checking account. My idea was to create this database in DB Pro so that I could add a search function to the database.
but I just can not get the numerical data to save to the text file correctly.
I even tried converting numerical data to string before the save and it still produces weird saves to the text file.

at wits end

Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 22nd Nov 2016 01:55
Open file to write 1, "test.txt"
Write string 1, str$(50.00, 2)
Write string 1, str$(25.36, 2)
Close file 1


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
-majic-
7
Years of Service
User Offline
Joined: 8th May 2016
Location: 3rd rock from the Sun
Posted: 22nd Nov 2016 11:31
Great Thank You !



Will have to go back and re-read those high dollar volumes again . . .
missed that part about the number of decimal places parameter

-majic-

-majic-
7
Years of Service
User Offline
Joined: 8th May 2016
Location: 3rd rock from the Sun
Posted: 22nd Nov 2016 14:12


these books and their examples ???

now that I have the data being written/read correctly , when it comes to the manipulation of that data [ add, subtract, etc.] it keeps rounding my numbers

the data is 68.14 - 50 = 18.14

but when the program does it , it does it this way

68 - 50 = 18

I guess I'm just dense

having rough time with the correct syntax when it comes to mathematical numbers

so many ways to manipulate numbers - real, float, integer, etc.

how does one keep the program (or is it my computer) from rounding the data ?

-majic-
-majic-
7
Years of Service
User Offline
Joined: 8th May 2016
Location: 3rd rock from the Sun
Posted: 22nd Nov 2016 15:04 Edited at: 22nd Nov 2016 15:32
dim A$(500):dim B#(500)

A$(1)="150248.39"
B#(1)=val(A$(1))

print B#(1);

should be 150248.39

prints on screen as 150248

???
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 22nd Nov 2016 17:15
Hmm looks like the type is being treated as integer.

Are you using the 9Ex version? There are reported bugs regarding floats and integers.

If you are using vanilla, you might try declaring the type on the array

dim B#() as float


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
-majic-
7
Years of Service
User Offline
Joined: 8th May 2016
Location: 3rd rock from the Sun
Posted: 22nd Nov 2016 18:50
Using MX18 r2 Dellware (aka Alienware) laptop
Win7 Pro SP1 64bit
DirectX 11

DB Pro version 1.077
DB Pro Editor by Synergy build Jun 23 2010


dim B#(10) as float or dim B(10) as float

no change - still has the rounding occurring
--------------------------------------------------------------

dim A$(500):dim B#(100)

type
amount# as float
endtype

A$(1)="150248.39"

amount# = val(A$(1))

B#(1) = amount#

print B#(1);

print amount#;

print abs(B#(1));

still rounds off the .39 when printed to the screen

grrrrrrr

seems like some where between the string var A$() to the float var B# the number is turned into an integer
and it shouldn't ; since the var is declared as float and a 'real' number is being used.


Derek Darkly
12
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 22nd Nov 2016 23:32 Edited at: 22nd Nov 2016 23:35
Interesting... the problem seems to be a glitch regarding the overall amount of digits that can be held in a float:



I didn't even know about this!
Send your parents to noisy sprite demo hell... enter the D-Zone
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 23rd Nov 2016 00:34 Edited at: 23rd Nov 2016 00:38
@ Derek Darkly

A float type variable is four bytes long and can only hold 7 significant digits, including the decimal point. So, a float value of 9999.34444 can only hold the four 9's the decimal point and 34. This is just how computer math works and is not related to the floating point issue with 9Ex.
-majic-
7
Years of Service
User Offline
Joined: 8th May 2016
Location: 3rd rock from the Sun
Posted: 23rd Nov 2016 00:38
Some of the mystery solved, this is from DB Pro Help files

FLOAT Range : 3.4E +/- 38 (7 digits)

so a declared float type can only hold 7 digits and

DOUBLE FLOAT Range : 1.7E +/- 308 (15 digits)

so a declared double float type can hold 15 digits

so now my problem is How do a declare a variable as a DOUBLE FLOAT type to get those 15 digits


A as double float

A = 123456.99

print A;
'''''''''''''''''''''''''''''''''''''''''''
A# as double float

A# = 123456.99

print A#;

????????????????

none of this does any good - the number printed to screen is still restricted to 7 digits
the above is how the DB Pro Help files and the $100 Volume 1 self study guide instructs on how to declare a DOUBLE FLOAT variable

A## as double float

A## = 123456.99

print A##;

DEFINITELY does not work

Need who ever is in charge of DB Pros' mathematical algorithm syntaxing to tell us

1) why the double float variable is still being restricted to just 7 digits when it is suppose to be 15

or

2) how to 'correctly' define a variable as DOUBLE FLOAT so DB Pro will print the 15 digits to screen

I do not even NEED 15 , all I want to print to screen is 9 ie: 123456.99

-majic-

WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 23rd Nov 2016 00:49
I would imagine double float variables are working fine. The problem most likely has to do the the double float being past to the print function as a float.

This seems to add digits.

-majic-
7
Years of Service
User Offline
Joined: 8th May 2016
Location: 3rd rock from the Sun
Posted: 23rd Nov 2016 00:59
putting numerical data into a string [ str$() ] turns that data into an integer , so it prints a 'lot' of unwanted digits

-majic-
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 23rd Nov 2016 01:04 Edited at: 23rd Nov 2016 01:12
Quote: "putting numerical data into a string [ str$() ] turns that data into an integer , so it prints a 'lot' of unwanted digits"


No, the value printed has a decimal point. Converting the value to a string seems to be adding the undefined digits.

-majic-
7
Years of Service
User Offline
Joined: 8th May 2016
Location: 3rd rock from the Sun
Posted: 23rd Nov 2016 01:17
yes - but all that is needed is two places past the decimal , not 15

looking like I will have to find some other programming language/software to use or just forget my project all together.
Won't do any good to continue working on it if this digit restriction/problem can not be resolved.

-majic-
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 23rd Nov 2016 01:59
Rounding the value to two decimal places shouldn't be difficult.
-majic-
7
Years of Service
User Offline
Joined: 8th May 2016
Location: 3rd rock from the Sun
Posted: 23rd Nov 2016 09:30
you would not think it would , but why is it so difficult to print a 9 digit number ?
And if a subroutine or function statements has to be created just to round numbers to two decimal places all the time - not worth it for a supposedly simple little checking account program.
I don't use other programs because none of them are as simple as what the Excel program I created is now. Plus I do not have to deal with the @#$%@#$# ADs if using freeware programs.
free my ass
Its just the Excel program has no searching capabilities other than for me to open each individual year and search each month manually.
I thought DB Pro with its muscle to create kickass 3D games could handle a simple little program/database of my checking account activities.

So sad ;(

-majic
-majic-
7
Years of Service
User Offline
Joined: 8th May 2016
Location: 3rd rock from the Sun
Posted: 23rd Nov 2016 13:08
Something to ponder . . .

When the 'Gods' of DB created their programming software, why did they choose 7 digits for Float and 15 digits for Double Float ? ?
The 'Gods' lived in Britannia ( I am assuming this since when I purchased DB Pro version 4 and later the two Volumes of DB Pro guides, it all came from there )
They are mathematically ruled ( aside from the Golden Number and Pi ) by the Metric System with 10 as its base.
So why did they not chose 10 for Float and 20 for Double Float . . . . .
Would definitely have negated the problem I am having now.

Hhhmmmmm



-majic-




is there a thread that deals solely on the mathematical, algorithmic, etc. to solve problems like this and improve the software ?

well maybe we already do - This Forum

Keep up the good work Everyone !



-majic-
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 23rd Nov 2016 14:49
print str$(A, 2)


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 23rd Nov 2016 15:00
Tbh, if you already have all of the data in excel, it's built in VBA may be a better fit. You can write a script to open and search across multiple files and sheets.


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
-majic-
7
Years of Service
User Offline
Joined: 8th May 2016
Location: 3rd rock from the Sun
Posted: 23rd Nov 2016 15:26
They definitely needed to add the use of the ,2 parameter into their Help and Guide books !

Thanks

Was thinking about VBA , but with each year in a separate workbook , thought it might be easier ( yeah right ) to just create a DB database to my own liking and import the data from CSV files.
Now barring any more DB Pro idiosyncrasies, just might "get r done".



Thanks again
-majic-
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 23rd Nov 2016 22:43 Edited at: 23rd Nov 2016 22:45
Thank You! Ortu. Wow! I completely forgot about that str$ parameter.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 24th Nov 2016 02:22
Keep in mind though that it simply truncates to the number of digits specified. It doesn't perform rounding.

3.519 -> 3.51


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
-majic-
7
Years of Service
User Offline
Joined: 8th May 2016
Location: 3rd rock from the Sun
Posted: 24th Nov 2016 10:34
well that did not last long



https://forum.thegamecreators.com/thread/218329
-majic-

Login to post a reply

Server time is: 2024-04-20 13:22:15
Your offset time is: 2024-04-20 13:22:15