Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello there i need to build a receipt number the values that am receiveing is this

RecieptCode LastRecieptNumber RecieptDisplayDigits
Rcp2008- 248 8


now the main prob is in receipdisplayDigits

i know in python if i write z*8 it will be zzzzzzzz
i want the same thing in C# but if i did it i will not be able to add the last reciept number/

how could this be done?
i have another method but am sure there would be a better one my method is to add the lastreceiptnumber
with 10^(receipt display digt) then i remove the 1 and write the receipt code it will look like this

the example above
10^8 = 100000000
100000000 + 249 (since it should be new receipt) = 100000249
Convert it to string and remove the 1 = 00000249
Then i add the receipt code

Is there better way taking into concideration the performance

Best Regards
Posted

1 solution

I really like the logic you have used in getting a value with 8 digits, it's great to see people thinking along those lines rather than expecting things to be done with a simple 'out the box' line of code (and thus never really learning how things are actually acheived).

But in instances like this one-liners are the way to go, so hope this helps...

int newNumber = lastReceiptNumber + 1;<br />string displayNumber = newNumber.ToString("D" + receiptDisplayDigits);


 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900