Is dBase file according to specifications - dbase

Please consider a DBF file with a field N(7,3). Is it allowed to store 9999.99 in such a field? In my mind 999.999 is the largest number allowed and -99.999 is the smallest.

You are correct on your 999.999. The full amount allows for 3 whole digits (or - plus 2 digits) decimal for 4th position and 3 more actual decimal.

Related

How to parse accounting number format in SQLite field?

I am a somewhat newbie to SQLite (and KMyMoney). KMyMoney (an open source personal finance manager) allows one-click exporting data into an SQLite database.
On browsing the SQLite database output, the dollar amount data is stored in a table called kmmSplits as several text fields in a strange format based on “value” and “valueFormatted” (see screen shot below). The “value” field is apparently written as a division equation (in a text format) which apparently yields the “valueFormatted” field (again in text format). The “valueFormatted is the correct number amount but the problem is that parenthesis are used to indicate a negative number instead of a simple minus in front of the value. This is apparently an accounting number format, but I don’t know how to parse this into a float value for running calculated SQL queries, etc. The positive values (without parenthesis) are no problem to convert to FLOATS.
I’ve tried using the CAST to FLOAT function but this does not do the division math, nor does it convert parenthesis into negative values (see screen shot).
The basic question is: how to parse a text value containing parenthesis in the “valueFormatted field (accounting money format) into a common number format OR, alternatively, how to convert a division equation in the “value” field to an actual calculation.
Use a CASE expression to check if valueFormatted is a numeric value inside parentheses and if it is multiply -1 with the substring starting from the 2nd char (the closing parenthesis will be discarded by SQLite during this implicit type casting):
SELECT *,
CASE
WHEN valueFormatted LIKE '(%)' THEN (-1) * SUBSTR(valueFormatted, 2)
ELSE valueFormatted
END AS value
FROM kmmSQLite;
Or, replace '(' with ''-'' and add 0 to covert the result to a number:
SELECT *,
REPLACE(valueFormatted, '(', '-') + 0 AS value
FROM kmmSQLite;

Reading hexdump: integers and reals

I wanted to know the structure of an unknown binary file generated by Fortran routine. For the same I downloaded hex editor. I am fairly new to the whole concept. I can see some character strings in the conversion tool. However, the rest is just dots and junk characters.
I tried with some online converter but it only converts to the decimal systems. Is there any possible way to figure out that certain hex represents integer and real?
I also referred to following thread, but I couldn't get much out of it.
Hex editor for viewing combined string and float data
Any help would be much appreciated. Thanks
The short answer is no. If you really know nothing of the format, then you are stuck. You might see some "obvious" text, in some language, but beyond that, it's pretty much impossible. Your Hex editor reads the file as a group of bytes, and displays, usually, ASCII equivalents beside the hex values. If a byte is not a printable ASCII character, it usually displays a .
So, text aside, if you see a value $31 in the file, you have no way of knowing if this represents a single character ('1'), or is part of a 2 byte word, or a 4 byte long, or indeed an 8 byte floating point number.
In general, that is going to be pretty hard! Some of the following ideas may help.
Can you give the FORTRAN program some inputs that make it change the length/amount of output data? E.g. can you make it produce 1 unit of output, then 8 units of output, then 64 units of output - by unit I mean the number of values it outputs if that is what it does. If so, you can plot output file length against number of units of output and the intercept will tell you how many bytes the header is, if any. So, for example, if you can make it produce one number and you get an output file that is 24 bytes long, and when you make it produce 2 numbers the output file is 28 bytes long, you might deduce that there is a 20 byte header at the start and then 4 bytes per number.
Can you generate some known output? E.g. Can you make it produce zero, or 256 as an output, if so, you can search for zeroes and FF in your output file and see if you can locate them.
Make it generate a zero (or some other number) and save the output file, then make it generate a one (or some other, different number) and save the output file, then difference the files to deduce where that number is located. Or just make it produce any two different numbers and see how much of the output file changes.
Do you have another program that can understand the file? Or some way of knowing any numbers in the file? If so, get those numbers and convert them into hex and look for their positions in the hex dump.

Why some decimal places truncated when insert 1234567890.12345678 into Decimal(18, 8) column in SQLite?

Below is my table create in SQLite database,
CREATE TABLE MyData(
Code VARCHAR(20),
Amount DECIMAL(18, 8)
);
then I insert 2 rows into the table.
INSERT INTO MyData
VALUES('A', 1.12345678);
INSERT INTO MyData
VALUES('B', 1234567890.12345678);
After that, execute a SELECT statement,
SELECT * FROM MyData;
SQLite returns the following result:
A|1.12345678
B|1234567890.12346
The DECIMAL(18, 8) suppose means precision=18 and scale=8, why some decimal places are truncated?
The details of how sqlite stores its data is described here. When you specify the DECIMAL column type, the storage for the column has NUMERIC affinity.
Section 2.0 has the following description about type affinity:
A column with NUMERIC affinity may contain values using all five
storage classes. When text data is inserted into a NUMERIC column, the
storage class of the text is converted to INTEGER or REAL (in order of
preference) if such conversion is lossless and reversible. For
conversions between TEXT and REAL storage classes, SQLite considers
the conversion to be lossless and reversible if the first 15
significant decimal digits of the number are preserved. If the
lossless conversion of TEXT to INTEGER or REAL is not possible then
the value is stored using the TEXT storage class. No attempt is made
to convert NULL or BLOB values.
This indicates that sqlite will attempt conversions between types, and if the first 15 digits of the number can be converted and reversed, the numbers are deemed to be equal. This effectively puts a limit on the available precision with which a number can be stored to 15 significant digits.
The wikipedia article on double precision floating point numbers has additional information which is useful when dealing with floating point numbers.

Always display two digits after decimal separator navision

I'm using Microsoft Navision 2009. I'm creating report that includes several number with decimal separator (double/float number in C#).
I'm stuck at the point where I want to display every number with two digits after decimal point.
Ex:
if number is 100, I want to display 100.00
if number is 100.5, I want to display 100.50
if number is 100.55, I want to display 100.55
if number is 100.505; i want to display either 100.51 or 100.50
Thank you in advance;
Language that I'm using is C/AL
Don't be lazy. Read essential manuals. Format function is your best friend in Nav.
strsubstno(text01,format(100.10,0,'<Precision,2:2><Standard Format,0>'))
Third argument of Format is actually the format of result text. <Precision,2:3> means that if first argument is decimal it will have from 2 to 3 (minimum 2 and maximum 3) digits in decimal part. <Standard Format,0> means that the rest of format will be standard.
More here!

Regular expression in ASP.net

I wrote regular expression for phone no as ^[0]\d{9,10} (phone no should start with 0). This works fine.
But I want to omit the option repeating 0's. i.e 0000000000
How can I add this bit to it.
^0(?!0*$)\d{9,10}$
might be what you want.
The first number is a 0.
The (?!0*$) negative lookahead ensures that the rest of the string is not all zeroes.
And finally \d{9,10} matches any 9 or 10 digits.
You could specify [1-9] as the second digit instead of \d, like so:
^[0][1-9]\d{8,9}$
(I presume the rest of the digits could still be zeros)
I do note that your phone number format is fairly limited. For example, it doesn't allow for international numbers (starting with a plus sign), nor for any common formatting characters such as brackets spaces or hyphens. It also assumes that all phone numbers will be 10 or 11 digits long, which is (mostly) true in the UK and probably other countries, but may not always be the case.
Depending on the requirements of your system, you may want to adjust to take some of those points into account.

Resources