This question already has answers here:
Is floating point math broken?
(31 answers)
Closed 3 years ago.
181.72 - 181.00 = 0.719999999999999
Why does Access do this? How can I get the correct answer of 0.72
Always use Currency as data type (also for your table fields) for amounts and quantities that require no more than four decimals:
Result = CCur(181.72) - CCur(181.00)
Result -> 0.72
For more decimals, use Decimal:
Result = CDec(181.59898) - CDec(181.00)
Result -> 0.59898
For use in a query, CDec will fail, so write a function to call it:
Public Function CVDec(ByVal Value As Variant) As Variant
Dim Result As Variant
Result = CDec(Value)
CVDec = Result
End Function
Related
This question already has answers here:
What is [:,:-1] in python? [duplicate]
(2 answers)
Python Difference between iloc indexes
(1 answer)
Understanding slicing
(38 answers)
Closed 6 months ago.
X = df_census.iloc[:,:-1]
y = df_census.iloc[:,-1]
what is the meaning of [:,:-1] in this and also [:,-1]
Following your example: [:,:-1]
The first argument is : which means to get all rows of the dataframe, and :-1 means to return all columns but the last one
In the case of just -1, it means to get the last column
This question already has an answer here:
counting the amount of True/False values in a pandas row
(1 answer)
Closed 5 years ago.
Return
0.0000
-0.0116
0.0000
0.0100
I have a dataframe of the format above and I am trying to count >0 and <0 with the following code
print ("Positive Returns:")
print((df['Return']>0.0).count())
print ("Negative Returns:")
print((df['Return']<0.0).count())
However both return 5119 which is my whole dataframe length
It is not counting correctly.. can anyone advise please?
Thankyou
*not really a duplicate since I am not asking for true/false value it can be >0.1 for example
Use sum for count boolean Trues which are processed like 1s:
print((df['Return']>0.0).sum())
print((df['Return']<0.0).sum())
This question already has an answer here:
How do I append a string/number to a string ?
(1 answer)
Closed 6 years ago.
I have label and I want to give it value of two elements that one of them NSInteger and the other string
_imgIndex.text = [#(index+1) stringValue]; //how to add string here?
It appears that you have an integer value (index) and a Obj-C string object (stringValue) and you want to concatenate them. There are lots of ways of doing this, here are two:
_imgIndex.text = [NSString stringWithFormat:#"%lu%#",index,stringValue];
The other technique would be to first convert the integer into a string, then concatenate the other string:
_imgIndex.text = [#(index).description stringByAppendingString:stringValue];
This question already has an answer here:
Fetching value from a number column removes 0 before decimal
(1 answer)
Closed 5 months ago.
Im using the following code to convert a number(38,2) to the format "XXX.XXX.XXX,XX":
TO_CHAR(number, '999G999G999G999G999G999G999D99')
Although, when the number is 0 or 0.XX the 0 is eaten up :
Input: 0
Result: ",00"
Expected Result: "0,00"
Input: 0.23
Result: ",23"
Expected Result: "0,23"
Why does this happen, is there a way of solving this without manipulating the result string ?
Use 0 instead of 9
TO_CHAR(0.00, '999G999G999G999G999G999G990D99')
0 ensures that if there is no digit in that place it'll display 0.
This question already has answers here:
Quickest way to convert a base 10 number to any base in .NET?
(12 answers)
Closed 9 years ago.
I am looking for a way to take a value from a text box and convert it into a base 2 number with 8 digits.So if they type in a text box 2 it would respond 00000010. or if they typed 255 11111111. etc... is there any way to do this.
Dim prVal As Integer
prVal = PrefixTxt.Text
Use the Convert.ToString method and specify the base as 2. This will convert an Integer value into a String in the specified base
Dim result = Convert.ToString(Integer.Parse(prVal), 2)
As #Dan pointed out if you want to force this to be width 8 use the PadLeft method
result = result.PadLeft(8, "0"c)
Convert.ToString(Integer.Parse(prVal), 2).PadLeft(8, '0')