Page 1 of 1
Print Using() / Round()
Posted: Thu May 12, 2005 7:10 pm
by PB&J Lover
Is there a text formating command like USING() in PB. I've not been able to locate it.
Here's how it works: P = USING("###.#", value.f)
so if value = 4.3452 then P will be 4.3.
This gives you a nice column when you print too.
Also, is there a Round() command that allows you to specify the number of decimals to round to?
Posted: Thu May 12, 2005 7:37 pm
by benny
There is a userlib called
PrintUsing which should do the job :
http://www.purearea.net/pb/download/use ... tUsing.zip
[edit]
Alternately, there is an updated version by Danilo of the SkunkLib which
also includes a PrintUsing :
http://www.purearea.net/pb/download/use ... unklib.zip
[/edit]
libraries
Posted: Thu May 12, 2005 8:14 pm
by PB&J Lover
Thanks.
How do you use a library?
Is there something for rounding numbers to a specific decimal?
What's all in the SkunkLib?
Posted: Thu May 12, 2005 8:17 pm
by Num3
StrF(Value.f [, NbDecimal])
Convert a float number into a string. A maximum number of decimal places can be specified. The number isn't rounded, but simply truncated.
Re: libraries
Posted: Thu May 12, 2005 8:50 pm
by benny
dbwisc wrote:Thanks.
You are welcome
dbwisc wrote:How do you use a library?
Just copy the Lib (the file with no suffix) in your:
[...]/PureBasic/PureLibraries/Userlibraries/
Folder. Important is that you have to
restart the compiler before
you want to use the new commands
dbwisc wrote:Is there something for rounding numbers to a specific decimal?
Try Num3's trick.
dbwisc wrote:What's all in the SkunkLib?
In this version there are just the two commands
-
StripAll(chain$ , search$ ) - Delete all the occurences of a string on
another string
-
Using( "#0-+" , number ) - Format a number as a string
Generally, every lib has a .chm-Help file included which gives a detailed
description of every command.
You can find numerous userlibs on PureArea.net :
http://www.purearea.net
Skunk Using() ERROR
Posted: Thu May 12, 2005 9:15 pm
by PB&J Lover
There are no examples in the Skunklib for using decimals. When I tried them I got strange results.
This:
Should not return this: " . 3"
The other one gave me all kinds of linking errors, so I'm 0 to 2.
But thanks.
Posted: Fri May 13, 2005 9:22 am
by benny
@dbwisc:
You are right ... I never used those libs - I just know of their existence.
However they do not seem to support floats. I am sorry for any inconveniences.
Hmm ... guess someone has to write a proper routine for this case. Like
parsing the pattern and apply the float-string to it ...
A did a quick try - it contains a lot of bugs and unchecked exceptions :
Code: Select all
; Print Using work-around
; May 2oo5 by benny!
;
; Note:
; Just a quick test!
; No syntax checking and so on ...
Procedure.s UsingF( fvalue.f, p$)
a$ = StrF( fvalue.f )
vMid.l = FindString( a$, ".", 1 )
pMid.l = FindString( p$, ".", 1 )
;prefix part
frA$ = Mid( a$, 1, vMid.l - 1 )
frP$ = Mid( p$, 1, pMid.l - 1 )
frA$ = Using( frP$, Val( frA$ ) )
;suffix part
suA$ = Mid( a$, vMid.l + 1, Len(a$) - vMid.l )
suP$ = Mid( p$, pMid.l + 1, Len(p$) - pMid.l )
If Len( suA$ ) = Len( suP$ )
ProcedureReturn frA$+"."+suA$
ElseIf Len( suA$ ) > Len( suP$ )
ProcedureReturn frA$+"."+Left(suA$, Len( suP$ ) )
Else
ProcedureReturn frA$+"."+Using ( suA$, Val ( suP$ ) )
EndIf
EndProcedure
Debug UsingF(201.13, "0000.000")
Debug UsingF(20012.3012, "0000000000.0")