How to get 6 decimal precision using vb.net as in this example (7090982.885183 (6 decimal places precision)) i.e i want to read the .885183 in my previous sample as 6 decimal only.
The javascript for the above looks like :
//declare variables and assign calculated values
var HashA = OrdNo * Amt;
var HashB = MerchID * Amt;
var HashC = MerchID * OrdNo;
var TotalHash = String((HashA + HashB + HashC) / (parseInt(MerchID) + parseInt(RCode)));
//assign only 6 decimal places value
if (TotalHash.indexOf(".") != -1)
TotalHash = TotalHash.substr(0,TotalHash.indexOf(".")+7);
else
TotalHash = TotalHash + ".000000";
document.form1.HashCount.value = TotalHash;
}
I need to read this no 7090982.8851830000011 as this format 7090982.885183
What about using % operater like
you have an variable a and variable decimalresult you should code it like this
decimalresult=a % 1000000
In this example it should be
decimalresult= 7090982.885183 % 1000000
decimalresult = 885183
If you have a Decimal and you want to get the value after the decimal dot, you can do
result = input - Math.Floor(input)
Related
How to use Right Shift operator in classic ASP. As suggested in In ASP, Bit Operator Left shift and Right shift , I used "\" for right shift operator. it gives me wrong result.
For example
in javascript, 33555758 >> 24 gives result 2.
But in Classic ASP 33555758 \ 24 gives division result.
Please help me on this.
Bitwise right shift >> is not equal to simple division \ by the given number, but by the given number of times by integer 2, which is binary 10. A bit shift moves each digit in a set of bits right. I.e. dividing by binary 10 removes a binary digit from the number and shifts digits right.
Example: 5 >> 1 = 2
5 00000000000000000000000000000101
5 >> 1 00000000000000000000000000000010 (2)
which is same as 5 / 2,
i.e. in your case it will be not 33555758 \ 24 but 24 times dividing 2. As there is no direct method in vbscript, it can be done as
Function SignedRightShift(pValue, pShift)
Dim NewValue, PrevValue, i
PrevValue = pValue
For i = 1 to pShift
Select Case VarType(pValue)
Case vbLong
NewValue = Int((PrevValue And "&H7FFFFFFF") / 2)
If PrevValue And "&H80000000" Then NewValue = NewValue Or "&HC0000000"
NewValue = CLng(NewValue)
Case vbInteger
NewValue = Int((PrevValue And "&H7FFF") / 2)
If PrevValue And "&H8000" Then NewValue = NewValue Or "&HC000"
NewValue = CInt("&H"+ Hex(NewValue))
Case vbByte
NewValue = Int(PrevValue / 2)
If PrevValue And "&H80" Then NewValue = NewValue Or "&HC0"
NewValue = CByte(NewValue)
Case Else: Err.Raise 13 ' Not a supported type
End Select
PrevValue = NewValue
Next
SignedRightShift = PrevValue
End Function
and used as
x = SignedRightShift(33555758, 24)
For more, see http://chris.wastedhalo.com/2014/05/more-binarybitwise-functions-for-vbscript/
Given the following code which encodes a number - how can I calculate the maximum number if I want to limit the length of my generated keys. e.g. setting the max length of the result of encode(num) to some fixed value say 10
var alphabet = <SOME SET OF KEYS>,
base = alphabet.length;
this.encode = function(num) {
var str = '';
while (num > 0) {
str = _alphabet.charAt(num % base) + str;
num = Math.floor(num / base);
}
return str;
};
You are constructing num's representation in base base, with some arbitrary set of characters as numerals (alphabet).
For n characters we can represent numbers 0 through base^n - 1, so the answer to your question is base^10 - 1. For example, using the decimal system, with 5 digits we can represent numbers from 0 to 99999 (10^5 - 1).
It's worth noting that you will not ever use some sub-n length strings such as '001' or '0405' (using the decimal system numerals) - so any string starting with the equivalent of 0 except '0' itself.
I imagine that, for the purpose of a URL shortener that is allowed variable length, this might be considered a waste. By using all combinations you could represent numbers 0 through base^(n+1) - 2, but it wouldn't be as straightforward as your scheme.
Can you use
irandom(-10,10)
to generate negative numbers? Or does this function provides only number >=0?
There is no information in documentation of GML.
A few examples:
a = -1 * irandom(10);
a = -irandom(10);
a = irandom(20) - 10;
a = irandom_range(-10, 10);
Y axis tick label should only show non decimal values / whole numbers as as series . if i set set TickUnit to 1 it should be 1,2,3,4,5,.. if i set Unit Ticks to 2 ..2,4,6,8,.. if i set to 5 5,10,15,20,25.
i set the Unit Ticks to 1 still it sometimes adding the decimal values also and showing 2.5 ,5.0,7.5,10.0,12.5......how to prevent this and show only whole numbers(Non decimal Numbers).?
option 1. store the number as an int, int num = (int)Math.floor(myDouble);
option 2. in your method make the parameter a double and inside the method cast it to an int
this will allow you to use the method with both a double and a int. Please keep in mind that this is C# code but java should be very similar.
private List<int> numberSeries(double aDouble)
{
List<int> number = new List<int>();
int base = (int)Math.floor(aDouble);
for(int x = 1;x++ < 10) //change 10 to whatever you want
{
number.Add(aDouble * x);
}
return number;
}
What i want is to retrieve quantity in database from piece and covert it to dozen. Then input as dozen and convert back to pieces and save to database again.
when I input data eg. 10.3, it should convert to 123 piece for me ((10 * 12) + 3). My code work well without my "If clause" but only when data was "single" type. It made error when I input integer number, so I added "If.." statement to check it first which is now the output was correct for Integer but incorrect when I input single number.
I have this code..
Function DzToPcs(val)
'If CLng(val) = val then <-- not work
'if Fix(val) <> val then <-- work but the output was not correct when input single type number.
if Int(vInt) = vInt then <-- work but the output was not correct when input single type number.
DztoPcs = val * 12
else
strInt = Cstr(val)
a = Split(strInt,".")
dz = a(0)
pcs = a(1)
getdz = Cint(dz)
getpcs = Cint(pcs)
DztoPcs = (getdz * 12) + getpcs
end if
I'm not sure what's wrong with your if statements (my VBScript is a little rusty), but you could try this alternative:
Function DzToPcs(val)
strInt = Cstr(val)
a = Split(strInt,".")
dz = a(0)
if UBound(a) > 0 then
pcs = a(1)
getdz = Cint(dz)
getpcs = Cint(pcs)
DztoPcs = (getdz * 12) + getpcs
else
DztoPcs = dz * 12
end if
end function