Convert double value with E-02 to "normal" value - vb6

I have the double value
3,64171229302883E-02
I would like to convert it so that the E-02 is gone and zeros are used instead.
How would I do that in VB6, please?

Assuming its in a string cast to Decimal ("," is locale specific, for me its ".")
?cdec("3.64171229302883E-02")
0.0364171229302883

Related

Convert double value with E-XX to “normal” value

I have the double value
EX. 2.77555756156289E-17
-8.48087032699772E-18
I would like to convert it so that the E-XX is gone and zeros are used instead.
How would I do that , please?

FoxPro convert currency to numeric

I'm using Visual FoxPro and I need to convert currency amount into numeric. The 2 columns in the table are tranamt(numeric,12,2) and tranamt2(character)
Here's my example:
tranamt2=-$710,000.99
I've tried
replace all tranamt with val(tranamt2)
and
replace all tranamt with val(strtran(tranamt2, ",",""))
both results give me zero. I know it has something to do with the negative sign but I can't figure it out. Any help is appreciated.
Try this:
replace all tranamt with VAL(STRTRAN(STRTRAN(tranamt2, "$", ""), ",", ""))
This removes the dollar sign and comma in one shot.
need to convert currency amount into numeric
tranamt(numeric,12,2) and tranamt2(character)
First of all a neither a Character Field Type nor a Numeric Field type (tranamt2) are Not a VFP Currency Field type
You may be using the value of a Character field to represent currency, but that does not make it a currency value - just a String value.
And typically when that is done, you do NOT store the Dollar Sign '$' and Comma ',' as part of the data.
Instead, you store the 'raw' value (in this case: "-710000.99") and merely format how that 'raw' value is displayed when needed.
So in your Character field you have a value of: -$710,000.99
Do you have the Dollar Sign '$' and the Comma ',' as part of the field data?
If so, to convert it to a Numeric, you will first have to eliminate those extraneous characters prior to the the conversion.
If they are not stored as part of your field value, then you can use the VAL() 'as is'.
Example:
cStr = "-710000.99" && The '$' and ',' are NOT stored as part of Character value
nStr = VAL(cStr)
?nStr
However if you have the Dollar Sign and the Comma as part of the field data itself, then you can use STRTRAN() to eliminate them during the conversion.
Example:
cStr = "-$710,000.99" && Note both '$' and ',' are part of data value
* --- Remove both '$' and ',' and convert with VAL() ---
nStr = VAL(STRTRAN(STRTRAN(cStr,",",""),"$",""))
?nStr
Maybe something like:
REPLACE tranamt WITH VAL(STRTRAN(STRTRAN(tranamt2,",",""),"$",""))
EDIT: Another alternative would be to use CHRTRAN() to remove the '$' and ','
Something like:
cRemoveChar = "$," && Characters to be removed from String
REPLACE tranamt WITH VAL(CHRTRAN(tranamt2,cRemoveChar,""))
Good Luck
A little late but I use this function call
function MoneyToDecimal
LPARAMETER tnAmount
LOCAL lnAmount
IF VARTYPE(tnAmount) = "Y"
lnAmount = VAL(STRTRAN(TRANSFORM(tnAmount), "$", ""))
ELSE
lnAmount = tnAmount
ENDIF
return lnAmount
endfunc
And can be tested with these calls:
wait wind MoneyToDecimal($112.50)
wait wind MoneyToDecimal($-112.50)
Use the built-in MTON() function to convert a currency value into a numeric value:
replace all tranamt with mton(tranamt2)

How to split string by HEX character

I need help to split string which contains a HEX character.
How to do it?
The code I have got doesnt work.
dim itr
itr="343434 XX7777777" ' SI
msgbox itr
dim scrns
scrns=Split(itr,"SI",-1,1)
msgbox scrns(1)
Define the character by its numeric value (0x0f for "shift in"):
scrns = Split(itr, Chr(&h0f))
In VBScript you define hexadecimal numbers by prefixing them with &h. The Chr function turns the number into the corresponding character.
As #JNevill pointed out in the comments you could also use the decimal instead of the hexadecimal value:
scrns = Split(itr, Chr(15))

Freemarker displays int value as double value(e.g. prints 0 as 0.00)

I am trying to write a freemarker template file having information about a table.
I have written '${noRows}' in the template for table rows count.
The noRows is a int value:
int noOfRows = myTable.getNumRows();
data.put("noRows", noOfRows);
The noOfRows is always an integer value but in the output file it is displayed as double value with ".00" appended to it.
How can I display the value as integer only.
If the value is indeed an integer, all you should need to do is
${noOfRows?string}
You can also use the Java decimal number format syntax:
${noOfRow?string["0"]}
Reference: http://freemarker.org/docs/ref_builtins_number.html#ref_builtin_string_for_number
Apparently, your number_format setting is set to 0.00 or like. (FreeMarker doesn't care about Integer VS Double when formatting numbers. It just have a single numerical type, and it formats all of them according to that setting.) Check it wherever FreeMarker is configured. As last resort, you can also set this setting in the template like <#setting number_format="0.##">. Last not least, as "sev" said, you can specify the format at each place individually.

C# Decimal Format 123.123,44 with Rounding

I need correct sample of using decimal format and decimal rounding to closest integer.
Sample1: I have number 123.345,51 result need to be 123.346,00
Sample2: I have number 123.345,49 result need to be 123.345,00
I found samples but they all use format with comma first 123,345.00 I need in first place point like 123.345,00
Tried with culture info but did not success ..
Sample code:
var amount = 123.345,77;
var cultureInfo = CultureInfo.GetCultureInfo("da-DK");
var formattedAmount = String.Format(cultureInfo, "{0:C}", amount);
When I need to convert formattedAmount to decimal its breaks... I am converting for Rounding values after ,
Solution is to enable users to input in format they want, like 123123,55 then use .Replace(",", ".") to replace , colon character with dot, after that made Decimal.Round and all problem are solved!

Resources