Main Menu

Leading Zero's

Started by baggey, November 23, 2012, 08:37:03 AM

Previous topic - Next topic

baggey

Is there a way of putting a given number of leading zero's on a decimal number? Without using string manipulation?

I looking for a quick simple way of achieving this!

Kind regards baggey
Jesus was only famous because of his dad

baggey

As this dosen't seem to work?

PlayBASIC Code: [Select]
text 1200,placeopcodeslne,right$(str$(pc),5)



Baggey
Jesus was only famous because of his dad

baggey

Here's a better example it can be done with HEX!?

PlayBASIC Code: [Select]
op_175:  // XOR A

nxtpc=1

if hex_or_dec = false
// Decimal representation
text 1200,placeopcodeslne,str$(pc)
text 1270,placeopcodeslne,str$(op_byte)
text 1460,placeopcodeslne,"XOR A"
op$=str$(pc)+" "+str$(op_byte)+" XOR A "
else
// Hex representation
text 1200,placeopcodeslne,right$(hex$(pc),4)
text 1270,placeopcodeslne,right$(hex$(op_byte),2)
text 1460,placeopcodeslne,"XOR A"
op$=right$(hex$(pc),4)+" "+right$(hex$(op_byte),2)+" XOR A "
endif

if monitormode=false

; What ever a is xor a with itself result's in 0 always!
fs = 0 ; S is set if result is negative; reset otherwise
fz = 1 ; Z is set if result is zero; reset otherwise
f5 = f5
fh = 0 ; H is reset
f3 = f3
fpv = 0 ; PV is set if overflow; reset otherwise
fn = 0 ; N is reset
fc = 0 ; C is reset

endif
exeTstates = 4
return



Baggey
Jesus was only famous because of his dad

buggage

Does
Digits$(InputValue, Digits)
not work anymore?

eg.

Text 194,160,"YOU SCORED "+Digits$(sc,6)

kevin

#4

QuoteIs there a way of putting a given number of leading zero's on a decimal number? Without using string manipulation?

   Nope,  regardless of what you give print or  text it's a string operation.   




PlayBASIC Code: [Select]
sc=123

Text 194,160,"YOU SCORED "+Digits$(sc,6)

sync
waitkey



produces

baggey

#5
Thankyou!

So to put leading Zero's we use Digits$

My Gosub XOR A Now looks like this:-

PlayBASIC Code: [Select]
op_175:  // XOR A

nxtpc=1

if monitormode=true

if hex_or_dec = false
// Decimal representation
text 1200,placeopcodeslne,digits$((pc),5)
text 1270,placeopcodeslne,digits$((op_byte),3)
text 1460,placeopcodeslne,"XOR A"
op$=str$(pc)+" "+str$(op_byte)+" XOR A "
else
// Hex representation
text 1200,placeopcodeslne,right$(hex$(pc),4)
text 1270,placeopcodeslne,right$(hex$(op_byte),2)
text 1460,placeopcodeslne,"XOR A"
op$=right$(hex$(pc),4)+" "+right$(hex$(op_byte),2)+" XOR A "
endif

endif

if execute=true

rega=0
; What ever a is xor a with itself result's in 0 always!
fs = 0 ; S is set if result is negative; reset otherwise
fz = 1 ; Z is set if result is zero; reset otherwise
f5 = f5
fh = 0 ; H is reset
f3 = f3
fpv = 0 ; PV is set if overflow; reset otherwise
fn = 0 ; N is reset
fc = 0 ; C is reset

endif
exeTstates = 4
return



Cheers  ;)

Baggey
Jesus was only famous because of his dad