Sample code here show below
lbUnit.Items.Add(String.Format("{0:n4}", dr1("unit_price")))
lbUnit1.Items.Add(String.Format("{0:n4}", dr1("unit_price")))
note that : dr1("unit_price") this unit_price is get from msSQL Server
this 2 statement show 4 decimal places
eg.
showing like this 0.013
but i want is 0.012543
when change to "{0:n4}" to "{0:n6}" and "{0:g}" also get same result is that any solution else can make it show all the decimal places?
Have you tried {0:0.000000} or {0:0.00####} which will only show more places if nescessary.
Use N6 as the numeric format string.
myDecimal.ToString("N6")
Or:
String.Format("{0:N6}", myDecimal)
Or:
Dim d As Double = 0.123
Dim sDisplayValue As String = d.ToString("0.000000")
Related
I have the following piece of code. I want to format numbers with string templates. One variable has 2 decimal places, the other 4 decimal places but they represent the same number 50000 (fifty thousand).
The first number is correctly formatted (German representation) 50.000,00, the other one however is formatted as 5 million 5.000.000,00!
DATA: lv_p2 TYPE p LENGTH 9 DECIMALS 2,
lv_p4 TYPE p LENGTH 14 DECIMALS 4.
START-OF-SELECTION.
lv_p2 = '50000'.
lv_p4 = lv_p2.
SET COUNTRY 'DE'.
"This is correctly formatted as 50.000,00
WRITE |{ lv_p2 NUMBER = ENVIRONMENT CURRENCY = 'EUR' }|.
"This is on the other hand interpreted as five million! 5.000.000,00
WRITE |{ lv_p4 NUMBER = ENVIRONMENT CURRENCY = 'EUR' }|.
Is this documented somewhere? What am I doing wrong here?
EDIT:
It looks like the problem is with the addition CURRENCY. If I don't use it, then the number is correctly formatted.
WRITE |{ lv_p4 NUMBER = ENVIRONMENT }|.
or WRITE |{ lv_p4 NUMBER = ENVIRONMENT DECIMALS = 2 }|.
Anyway looks like some kind of a bug.
I believe this behaviour is documented.
ABAP Documentation - WRITE, format_options - CURRENCY cur
When CURRENCY is added:
"For data objects of type p, the decimal places determined by the
definition of the data type are ignored completely. Independently of
the actual value and without rounding, decimal separators and
thousands separators are inserted between the digits in the places
determined by cur."
Shortly: if CURRENCY is added (by WRITE), the number of decimal places is determined by the currency (in this case EUR has 2 decimal places), so the value 50.000,0000 will be 5.000.000,00. Same length (9 digits) only the number of decimals will be different.
I am having a problem creating a function for SQL server query in php or changing how the value output I get in index page where the result would be something like = 25.879999999999999 when I want it as 25.87
when ap.idproduct = 1 then cast(tr.PreviousBalance as float)/100
else cast(tr.FinalBalance as float)/100 end as balance_before,
need float limited to 2 decimals or a function ( please explain how it is used as I kinda new to PHP)
FIX :
ROUND(cast(tr.PreviousBalance /100 as float), 4)
Wrapping cast in round
In the database, there is a number (rawresult) and a number format (format) in a single row. I want to format the rawresult to how format says it should be with a single query. This is a database that already exists and we can't modify it.
Example 1: (rawresult = 1.254; format = 0.0), output should be 1.3
Example 2: (rawresult = 1.254; format = 0.00000), output should be 1.25400
Example 3: (rawresult = 10.254; format = 0.000), output should be 10.254
The format field can be null, 0, 0.0, have 6 decimal places, or anything in between. I have no idea how to go about doing this with a single SQL query. Sometimes, format will be null, but that part I can actually handle. Basically, I need to round it if format has less decimal places than rawresult, or add trailing 0s if format requires more decimal places than rawresult has.
Thanks!
A possible approach is the FORMAT() function, but the format must contain a valid .NET Framework format string:
SELECT FORMAT([rawresult], [format]) AS [result]
FROM (VALUES
(1.254, NULL),
(1.254, '0.0'),
(1.254, '0.00000'),
(10.254, '0.000')
) v ([rawresult], [format])
Result:
result
-------
1.254
1.3
1.25400
10.254
I have a select statement that populates a datagridview:
da = New SqlDataAdapter("SELECT Month, (Sum(IncCnt)) as IncCnt, (Sum(AllFCR)) as AllFCR, (Sum(Prv)) as Prv, ((SUM(IncCnt)-SUM(AllFCR))/(SUM(IncCnt)-SUM(Prv))) as FCR, ((SUM(ASAT)+SUM(CSAT))/(SUM(SurveyTtl))) as CSAT FROM [tblPLOps_Data] group by Month", ScoreConn)
However, it displays a 0 for FCR and CSAT although you can do the math from the first three columns and see that FCR should be .89
I need to display as a percent anyway so I tried:
DataGridView1.Columns(4).DefaultCellStyle.Format = "p"
But that just returned 0%, I also changed to decimal and that just returned 0.0
Then I read online and tried:
DataGridView1.AutoGenerateColumns = True
But that didn't help either, anyway how to get it to return a value?
((SUM(IncCnt)-SUM(AllFCR))/(SUM(IncCnt)-SUM(Prv)))
and
((SUM(ASAT)+SUM(CSAT))/(SUM(SurveyTtl)))
are using INTEGER division since they are both integers. You need to cast (one of) them to decimal first, ideally the deominator. Here's an example...
select 1/2 RETURNS 0
select 1/2.0 RETURNS 0.5000000
select 1.0/2 RETURNS 0.5000000
Something like...
((SUM(IncCnt)-SUM(AllFCR))/(cast(SUM(IncCnt)-SUM(Prv) as decimal(16,2))))
and
((SUM(ASAT)+SUM(CSAT))/(cast(SUM(SurveyTtl) as decimal(16,2))))
Ok... I guess my brain has finally gone on vacation without me today. I have extracted 2 fields from a website and I get this string
vData = "Amount Owed [EXTRACT]$125.00[EXTRACT]
vData was declared as an array (string).
I split vData on [EXTRACT] and I end up with 2 string variables like this:
varA = "Amount Owed"
varB = "$125.00"
To parse varB, I use
Dim varC as Currency
varC = val(varB)
I want to use varC in an If statement:
If Val(VarC) <> 0 Then
I was expecting varC to be 125 but when I look at varC is 0. I can't figure out why varC = 0 and not 125.
Use CCur(varB) instead of Val(varB). CCur converts to a Currency type, so knows about $ and other things.
Explanation from the MS docs:
... when you use CCur, different decimal separators, different thousand separators, and various currency options are properly recognized depending on the locale setting of your computer.
Val is only looking for straight numbers:
The Val function stops reading the string at the first character it can't recognize as part of a number. Symbols and characters that are often considered parts of numeric values, such as dollar signs and commas, are not recognized.