# Calculating Hash Total 11 digits long

This is a discussion on Calculating Hash Total 11 digits long within the Excel Questions forums, part of the Question Forums category; Hi, I have a workbook that creates an AFI file. A trailer record is required that needs a hash total ...

1. Hi, I have a workbook that creates an AFI file. A trailer record is required that needs a hash total being the first 11 digits of a number.

The numbers start as a string but I need to total the strings as a number so I have declared a variable sngHash to do this. Once I have the hash total it needs to be shortened to 11 digits by removing the highest digit of the number.

Trouble is, the Single data type is using scientific notation so when I want to place the number in the trailer it has 1.696781E+11.

OK, different tack, so I next declared a variable cstrHash to convert the number to a string but the number turns into 169781000000 ! which is definitely not correct (should be 149678133877 by my hand written arithmetic)

1) Why is single doing this instead of putting the actual number and
2) How can I add up all the strings to get a total

Any help would be gratefully received

Code (edited to remove unnecssary code)...
Code:
```Dim sngHash As Single
Dim strHash As String
Dim Card As String
Dim Finish As Integer

n = 2
Finish = Selection.Rows.Count
Count = 0
For n = n To Finish
Card = Range("b" & n).Value & Space(19 - Len(Range("b" & n).Value))

Count = Count + 1
sngHash = Val(Left(Card, 11)) + sngHash

Next n

strHash = CStr(Format(sngHash, "000000000000"))
If Len(strHash) > 11 Then
strHash = Right(strgHash, 11)
End If```

2. Hi all, cracked it. If you use the Currency data type it can handle the 12 digits so I have it working now.

However I would still like to know why Single was putting the number in scientific notation and how you can prevent it from doing so.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•