flat assembler
Message board for the users of flat assembler.
Index
> Main > Procedure to add commas into number strings |
Author |
|
me239 01 Aug 2011, 01:05
Hey everyone! I was wondering if anyone had any example procedures for adding commas into number strings eg. 12345 = 12,345
Thanks! |
|||
01 Aug 2011, 01:05 |
|
me239 01 Aug 2011, 02:04
edfed wrote: use something like this: Thanks, but is there anyway to convert a number of any size without using a string with preexisting commas? BTW I'm still in 16 bit realmode. |
|||
01 Aug 2011, 02:04 |
|
bitshifter 01 Aug 2011, 02:16
You want to put comma in every 3 positions?
Thousands... Hundred Thousands... 12,345,678 |
|||
01 Aug 2011, 02:16 |
|
me239 01 Aug 2011, 02:23
bitshifter wrote: You want to put comma in every 3 positions? |
|||
01 Aug 2011, 02:23 |
|
edfed 01 Aug 2011, 11:20
to use commas, you should add a test for comma like this:
Code: .loop: dec ebx cmp byte[ebx],'.' jne @f dec ebx @@: cmp [ebx],',' ;test for comma jne @f dec ebx @@: for a number like 4,143,321.433 the string will look like this: Code:
db 'x,xxx,xxx.xxx'
if you give a string like this: Code:
db ',,,,,,,,,,,,,x'
the function will give this result for the number 1234567 Code:
db '1,2,3,4,5,6,7'
but it is possible to modify the algo Code: .loop: dec ebx cmp byte[ebx],'.' je .loop cmp byte[ebx],',' je .loop and then, the result of number 12345 with string 'X,,X,,x,,,,,x,,,,,x' will be '1,,2,,3,,,,,4,,,,,5' |
|||
01 Aug 2011, 11:20 |
|
vid 01 Aug 2011, 16:06
libc's sprintf or fasmlib's str.ins plus simple loop
|
|||
01 Aug 2011, 16:06 |
|
DOS386 02 Aug 2011, 13:09
me239 wrote: Hey everyone! I was wondering if anyone had any example procedures for adding commas into number strings eg. 12345 = 12,345 Thanks! NO But I have cool code adding apo's instead ... so your "12,345" won't become "12+345/1'000" (imagine you get just cca 12 $$$ instead of 12'345 $$$ for your work ) |
|||
02 Aug 2011, 13:09 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.