How to disable scientific notation in .AsString in Delphi? - delphi

Hi
I want to get numbers from database, for example, if the number in database is 44.7890000000, I would like to get a string 44.789, the same 0.0010000000 -> 0.001, just keep the numbers and trim the tailing '0'.
I use this code:
qrySth.Fields[i].AsString - it does its job but I find for very small numbers like 0.0000010000 it becomes 1E-6. Is there a way I could disable the scientific notation for this AsString method?
Thanks!

As an alternative to setting the field's DisplayFormat property, you can read from AsFloat and pass the value directly to FormatFloat. It uses the same format pattern.

Related

FME change data format from string to numeric

Struggling with a really simple problem; I need to convert attribute from string to numeric in FME. have tried using the arithmetic editor, but every time I export to GIS I get string. It seems when one uses the statistics calculator you get numeric.
Any ideas? As I am all out of them.
Ashton

Renaming fragments on SPSS

I am not used to SPSS so this question will sound stupid:
I need to change fragments of a cell in spss, exemple:
'1.28'
'2.69'
'3.57'
to
'a.28'
'b.69'
'c.57'
What's the best way to do it?
Tks.
This is assuming the variable you want to recode is called 'VarA', and that it is numeric.
This creates a copy of the variable, converts it to a string, and then uses those values to create a new version that is recoded.
RECODE VarA (ELSE = COPY) INTO VarA_String.
ALTER TYPE VarA_String(A8).
EXECUTE.
COMPUTE VarA_r=REPLACE(VarA_String,'1.','a.').
COMPUTE VarA_r=REPLACE(VarA_String,'2.','b.').
COMPUTE VarA_r=REPLACE(VarA_String,'3.','c.').
EXECUTE.
The syntax is a little different in SPSS Modeler and bear with me as I can only attach one image until I have a certain reputation on SO.
After you convert VarA into a string (which I called to_str) you can use the replace command to change part of the substring, ie:
to_string(VarA)
for the first Derive node, and:
replace('1.','a.',to_str)
for the second Derive node, this command replaces all occurrences of SUBSTRING1 with SUBSTRING2 in STRING and you will get the same result but in Modeler, see the sample stream here
Assuming that these are strings, see the replace function in COMPUTE. If there are just a few, though, just edit the cells in the Data Editor.

How do I avoid errors when converting strings to numbers if I don't know whether I have floats or integers?

I have stringgrid on delphi form and i am trying to divide values of one cell with value of another cell in another column.
But the problem is, stringgrid cells are populated with different types of numbers, so I am getting ConvertErrors.
For example the numbers in cells can look like
0.37 or 34 or 0.0013 or 0.00 or 0.35 or 30.65 or 45.9108 or 0.0307 or 6854.93.
In another words I never know is it going to be real, float, integer or any other kind of type in those cells.
I have looked everywhere on internet but no luck. Anyone any ideas. By the way I am not exactly Delphi expert. Thanks.
For each string, convert it first to a float value using StrToFloat function in SysUtils.pas . This should allow for any numerical type to be dealt with (unless you have something unusual like complex numbers). As you have some zero values in your list above you should also ensure that you check for divide by zero conditions as this will also potentially throw an exception.
SysUtils has many functions such as TryStrToFloat, TryStrToInt, TryStrToInt64 etc for this purpose. These functions accept a reference parameter (var parameter) for returning the converted value and function itself returns true if the conversion is successful.
If you are sure that the string has a valid number then you can check the input string to see if it has a decimal point before deciding which function to use.
Treat all the numbers as float. Use StrToFloat, divide the numbers, and then convert the result back to string with FloatToStr. If the result is an integer, no decimal point would be produced.

Convert Text value to Integer using IValue converter

In my application i am binding a integer to a gridview column.
Scenario : In the cell edit mode of gridview, if the user types some string values like A+,A. i want text to convert it automatically to integer value.
I am having a collection where each string value will be having a integer assigned.
In the converter i want to check for that and show its corresponding integer value.
Can it be done using IValueConverter
Yes, it makes sense to do this in a value converter.
Out-of-the-box, .NET does not provide any classes or methods for parsing the expression into its numerical equivalent, but you should be able to use numerical parsing libraries like for example NCalc or Simple Math Parser to "do the job" for you.
I honestly don't know if these libraries are immediately available for Silverlight, but if not it is probably worth the effort to port them to SL yourself, rather than writing your own math parser.

AnsiStrIComp fails comparing strings in Delphi 2010

I'm slightly confused and hoping for enlightenment.
I'm using Delphi 2010 for this project and I'm trying to compare 2 strings.
Using the code below fails
if AnsiStrIComp(PAnsiChar(sCatName), PAnsiChar(CatNode.CatName)) = 0 then...
because according to the debugger only the first character of each string is being compared (i.e. if sCatName is "Automobiles", PAnsiChar(sCatName) is "A").
I want to be able to compare strings that may be in different languages, for example English vs Japanese.
In this case I am looking for a match, but I have other functions used for sorting, etc. where I need to know how the strings compare (less than, equal, greater than).
I assume that sCatName and CatNode.CatName are defined as strings (= UnicodeStrings)?. They should be.
There is no need to convert the strings to null-terminated strings! This you (mostly) only need to do when working with the Windows API.
If you want to test equality of two strings, use SameStr(S1, S2) (case sensitive matching) or SameText(S1, S2) (case insensitive matching), or simply S1 = S2 in the first case. All three options return true or false, depending on the strings equality.
If you want to get a numerical value based on the ordinal values of the characters (as in sorting), then use CompareStr(S1, S2) or CompareText(S1, S2). These return a negative integer, zero, or a positive integer.
(You might want to use the Ansi- functions: AnsiSameStr, AnsiSameText, AnsiCompareStr, and AnsiCompareText; these functions will use the current locale. The non Ansi- functions will accept a third, optional parameter, explicitly specifying the locale to use.)
Update
Please read Remy Lebeau's comments regarding the cause of the problem.
What about simple sCatName=CatNode.CatName? If they are strings it should work.

Resources