13 digit number rounding and full visible

BlitzMax Forums/BlitzMax Beginners Area/13 digit number rounding and full visible

Philip7(Posted 2008) [#1]
Hi,

I'm new to Blitzmax (... Blitz-anything actually).
Currently i'm in the building a 2D side scrolling adventure fase (read: beginner) and somehow i ended up making an application for work. But making this application will give me more time at work.... to read the Blitz forum :)

I'm using MaxGui to show 2 inputboxes.

In inputbox 1 a user types a 13 digit number
In inputbox 2 (outputbox) i show the number converted to a 12 digit number.

Why? Well at my work we have a unique identifier for persons but we are not allowed to communicate that number to the outside world. We send information with a 'encryption', a math conversion to a different number (13 digits) to keep the person unique but to make identifying the person very difficult.
In some cases we get the encrypted number back and we need to decrypt it. But because the math conversion needs to be kept on a 'need to know' basis i have to decrypt the number for others.
To save myself and my colleges from this menial work i'm making a conversion tool. It's easy, i made it for myself in Excel but i can't give that to others because they can see the formula.

I ran into 2 problems:

1. After reading a lot on the forum i used different rounding functions but none work with 13 digit numbers.

2. After conversion the number is displayed like this: 5.08356485e+010. But it should be like this: 123456789012

Does anyone have an idea how to fix this?


Gabriel(Posted 2008) [#2]
Use doubles instead of floats. Not sure if you'll quite manage 13 digits, but you should get closer.


Kurator(Posted 2008) [#3]
I think there is a funny behavior within the compiler:

Try this:

SuperStrict

Local Test1:Long = 1234567890:Long
Local Test2:Long = 12345678901:Long
Local Test3:Long = 123456789012:Long

Const MAXLONG:Long=$7fffffffffffffff:Long
Const MINLONG:Long=$8000000000000000:Long

Print "A long can have the maximum value of:"+MAXLONG
Print "A long can have the minimum value of:"+MINLONG

Print Test1
Print Test2
Print Test3



Philip7(Posted 2008) [#4]
@Gabriel: thanx for your input but i already use Double.

@robobimbo: I will try it at home as soon as i'm done with work.. which isn't for another 8 hours. But shouldn't i use Double instead of Long?

I really hope that if i can make this in Excel it's also possible in BlitzMax. Anyone an idea on how to display the full 12 digits output instead of the 1,345634E23 output?


Kurator(Posted 2008) [#5]
do you generate integer numbers oder do you have to handle decimal numbers? (floating point)


Brucey(Posted 2008) [#6]
This converts doubles in various ways between strings/doubles, and always appears to display as expected :
SuperStrict

Local bigNum:Double = 1234567890123:Double

Local bigString:String = "1234567890123"

Print bigNum
Print bigString

Local test:String = bigNum

Print test

test = String.FromDouble(bigNum)

Print test

bigNum = test.ToDouble()

Print bigNum

test = String.FromDouble(bigNum)

Print test

' some math
bigNum = bigNum/10

Print bigNum

bigNum = Floor(bigNum)

Print bigNum

test = String.FromDouble(bigNum)

Print test

my output, on XP SP2, bmx 1.30
1234567890123.0000
1234567890123
1234567890123.0000
1234567890123.0000
1234567890123.0000
1234567890123.0000
123456789012.30000
123456789012.00000
123456789012.00000



Philip7(Posted 2008) [#7]
@Brucey:

You are my saviour! Many thanx.

Somehow my gut feeling tells me the Floor function will just discard whatever is behind the komma, is my assumption right?

I need to round the number up where the numbers behind the komma are >= .5 and down where < .5.


Brucey(Posted 2008) [#8]
You can always add .5 and then Floor().


Philip7(Posted 2008) [#9]
Eh... yeah that will actually work, thanx.
Next time i'll think before asking.

You just made yourself some excellent advertisement for you mods Brucey :)