Thanks, guys. Pat yourself on the back- I wrote my instructor
about this issue I wrote here before and she was stumped.
She had no idea!
I am sending her the correct example for her to see.
Thanks, and happy holidays everyone.
Robert
------------------
Announcement
Collapse
No announcement yet.
Formatting question - PB Dos 3.5
Collapse
X
-
Try this
Code:10 'Show us the problem... 20 LatVal## = 32.82736451177 :'I want LatVal$ to be 32.8273 '30 LatVal$ = USING$("00.0000",LatVal##) '40 Print LatVal$'pbvUsingChrs = "*$.," PRINT FourDigits(LatVal##) ' prints 32.8273 (without rounding) ' this function has no rounding FUNCTION FourDigits(BYVAL X AS EXTENDED) AS STRING FUNCTION = STR$(INT(X*1D4)/1D4) END FUNCTION
Arthur Gomide
Como diria nosso profeta da bola, Dadá Maravilha: "Para toda Problemática existe uma Solucionática!"
Leave a comment:
-
Two problems
USING$("00.0000",LatVal##)
00.0000 is not a formating string you need to use # for
character positions
30 LatVal$ =USING$("##.####",LatVal##) is the correct form
however in PBDOS this will be rounded, so the result is
32.8274 If rounding is acceptable.
to prevent rounding, take one extra number and slice it off
leaving this
10 'Show us the problem...
20 LatVal## = 32.82736451177 :'I want LatVal$ to be 32.8273
30 LatVal$ = left$(USING$("##.#####",LatVal##),7)
40 Print LatVal$
------------------
http://www.allthingsspiny.co.uk
Leave a comment:
-
Originally posted by Robert E. Carneal:
USING$ is still giving me a problem.
30 LatVal$ = USING$("##.####",LatVal##)
For more examples about the use of USING$() function see the PRINT USING statement help.
------------------
Arthur Gomide
Como diria nosso profeta da bola, Dadá Maravilha: "Para toda Problemática existe uma Solucionática!"
[This message has been edited by Arthur Gomide (edited December 28, 2006).]
Leave a comment:
-
USING$ is still giving me a problem. Here is what I have:
10 'Show us the problem...
20 LatVal## = 32.82736451177 :'I want LatVal$ to be 32.8273
30 LatVal$ = USING$("00.0000",LatVal##)
40 Print LatVal$
I get Error 5: Illegal function call for the error.
I sure hope I am not mis-reading the directions for this
function!I don't want any rounding, just the first four decimal
places. Thank you.
Robert
------------------
[This message has been edited by Robert E. Carneal (edited December 28, 2006).]
Leave a comment:
-
Roger, PB/DOS 3.5 has a USING$...
Code:[ ALT-F1 ]„Ÿ[ SHIFT-F1 ]PowerBASIC Help System USING$ function Purpose: Formats numeric or string data like PRINT USING. Syntax: s$ = USING$(format string, expression) expression is a numeric or string expression, and format string is a string expression which specifies how expression is to be formatted. USING$ follows exactly the same rules as the format strings in the PRINT USING statement, returning expression formatted according to format string.
(Ok, so you can't have multiple masks for positive, negative or zero numeric variable but it's not like that is such a big thing to code...)
[This message has been edited by Michael Mattias (edited December 28, 2006).]
Leave a comment:
-
I ran into the same issue a couple weeks back. It had been like
a year since using PBDOS and I thought it had one too. Maybe there
will be one in PBDOS 4? Hope so as USING didn't do everything the
way I wanted. There have been a few other improvements in the Windows
versions of the BASIC commands/structures used in PBDOS too that would be nice.
------------------
If you aim at nothing...you will hit it.
Leave a comment:
-
you might try USING$, it works like FORMAT$ except that the format
string is before the expression, so your code might look like:
LatV$ = Using$("##.####", LatVal)
or something like that.
buck
------------------
[This message has been edited by Buck Huffman (edited December 18, 2006).]
Leave a comment:
-
Originally posted by Robert E. Carneal:
can I "add-in" the function in someway?
Code:LetVal# = 32.34 LatV$ = fnFormat$(LetVal#,2%,4%) PRINT LatV$ ' prints '32.3400' LetVal# = 32.123456789 LatV$ = fnFormat$(LetVal#,2%,4%) PRINT LatV$ ' prints '32.1235' LetVal# = 1234.123456789 LatV$ = fnFormat$(LetVal#,5%,4%) PRINT LatV$ ' prints ' 1234.1235' ' note the bankers ^ rounding ' effect at caret position 'from my old Turbo Basic library DEF fnFormat$(DoubleArg#, BeforeDot%, AfterDot%) ' Esta função retorna o argumento aredondado num campo tipo #####.## LOCAL Temp$, Campo% LET Temp$ = fnEncode$(DoubleArg#, AfterDot%) LET Campo% = BeforeDot% + AfterDot% + 1% 'IF LEN(Temp$) > Campo% THEN ' IF Campo% < 8 THEN ' fnFormat$ = STRING$(Campo%, CHR$(35)) ' ELSE ' fnFormat$ = "Overflow!" ' END IF ' EXIT DEF 'END IF WHILE LEN(Temp$) < Campo% LET Temp$ = CHR$(32) + Temp$ WEND fnFormat$ = Temp$ END DEF 'Format$ DEF fnEncode$(Arg#, Dec%) ' esta função retorna, numa string, o valor do argumento arredondado LOCAL Sinal%, Ponto%, Tam%, Temp#, Temp$ LET Sinal% = SGN(Arg#) IF Sinal% = 0% THEN fnEncode$ = " 0." + STRING$(Dec%, "0") EXIT DEF END IF LET Temp# = ABS(Arg#) IF Temp# >= 1d16 THEN fnEncode$ = STR$(Arg#) EXIT DEF END IF LET Temp$ = STR$(Temp# * EXP10(Dec%) + .5#) LET Temp$ = RIGHT$(Temp$, LEN(Temp$) - 1%) LET Ponto% = INSTR(Temp$, ".") IF Ponto% <> 0% THEN LET Temp$ = LEFT$(Temp$, Ponto% - 1%) IF Temp$ = "" THEN LET Temp$ = "0" WHILE LEN(Temp$) < Dec% LET Temp$ = "0" + Temp$ WEND LET Tam% = LEN(Temp$) IF Tam% = Dec% THEN LET Temp$ = "0." + Temp$ ELSE IF Dec% <> 0% THEN LET Temp$ = LEFT$(Temp$, Tam% - Dec%) + "." + RIGHT$(Temp$, Dec%) END IF IF Sinal% < 0% THEN LET Temp$ = "-" + Temp$ 'ELSE LET Temp$ = " " + Temp$ fnEncode$ = Temp$ END DEF 'Encode$
Arthur Gomide
Como diria nosso profeta da bola, Dadá Maravilha: "Para toda Problemática existe uma Solucionática!"
[This message has been edited by Arthur Gomide (edited December 18, 2006).]
Leave a comment:
-
I think that PRINT USING will do just what you want.
Best regards,
Bob Zale
PowerBASIC Inc.
------------------
Leave a comment:
-
Formatting question - PB Dos 3.5
I thought PB (Dos)had a FORMAT command? That is, if I have the
following:
input #1, LatVal :' We will assume the value is 32.34
LatV$ = Format$(LatVal,"00.0000") :'Now LatVal$ contains 32.3400
'next time around, when I read the next record, I might see:
input #1, LatVal :' Assume LatVal = 32.123456789
LatV$ = Format$(LatVal,"00.0000")
In the last case, I want LatV$ to be 32.1234, four decimal
places. I could multiply the value by 10,000, take the INT
of it, and then divide so it gets the decimal portion back, but
I was hoping for a more accurate way.
If PB (dos) does not have this function, can I "add-in" the
function in someway?
Thanks.
Robert
------------------
Tags: None
Leave a comment: