Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out how many thousands and hundreds and tens are there in a amount

I am having a asp application and in that amount column is there. I need to find out how many thousands and hundreds and tens are there in that amount

For example

if i am having amount as 3660 means 1000's - 3 100's - 6 10's - 6

like this i need

Can any body help me

like image 863
Suhail Avatar asked Nov 16 '13 06:11

Suhail


3 Answers

The simple answer is to divide the number by 1000 whatever is the quotient that is the number of 1000's in the amount. Then divide the remainder with the 100's the quotient will be the number of 100's. And then again divide the remainder with 10, the quotient will be the number of 10's

Something like this:

quotient = 3660 / 1000;     //This will give you 3
remainder = 3660 % 1000;    //This will give you 660

Then,

quotient1 = remainder/ 100;     //This will give you 6
remainder1 = remainder % 100;    //This will give you 60

And finally

quotient2 = remainder1 / 10;     //This will give you 6 
like image 144
Rahul Tripathi Avatar answered Sep 21 '22 02:09

Rahul Tripathi


Is it not easier to use type coercion and change the data type to string?

Then you can easily check the value by checking the value at selected index position,

var number = 1234;
number2 = new String(number);
var thousands = number2[0];
var hundreds = number2[1];

and so on....

It may not be usable in what you're doing, it was for me :)

like image 32
blpanther Avatar answered Sep 20 '22 02:09

blpanther


If the "javascript" tag is the correct one, then you've already gotten some answers. If the "asp-classic" tag is actually the correct one, then chances are your scripting language is VBScript, not Javascript.

Did you just pick multiples of 10 as an example, or is that the actual multiple you're looking for? Because if it's the latter, then all you need to do is split the number into digits — that's what the base 10 number system means, after all.

Function SplitNum(theNum)
   dim L, i, s, n
   n = CStr(theNum)
   L = Len(n)
   s = ""
   for i = 1 to 3
      if s <> "" then s = "," & s
      if i >= L then
        s = "0" & s
      else
        s = Left(Right(n,i+1),1) & s
      end if
   next
   if L > 4 then s = left(n,L-4) & s
   SplitNum = s
End Function

If your actual divisors are something other than multiples of 10, you'll need to do arithmetic. The integer division operator in VBScript is \. (Integer division is basically the "opposite" of the modulus function.)

Function GetMultiples(theNum)
   dim q, r
   q = theNum \ 1000 & ","
   r = theNum Mod 1000
   q = q & r \ 100 & ","
   r = r Mod 100
   q = q & r \ 10
   GetMultiples = q
End Function
like image 25
Martha Avatar answered Sep 23 '22 02:09

Martha