# How to calculate the right amount of a token to use in 0x quote endpoint

I'm trying to use 0x to buy tokens with ETH. I'm following the sample at https://0x.org/docs/guides/swap-tokens-with-0x-api#swap-eth-for-1-dai.

I got the token address, and the decimals. let's say USDC and 6. And let's say I want to buy 1 USDC. How do I calculate the value I need to pass to buyAmount? I tried several things: passing '1', passing '1000000' (1 and 6 0s). I tried 5 0s. When it hits MetaMask it's always the wrong amount: 10 or 100 etc. And the fee is crazy (\$39 in gas to buy 10 USDC?).

It's even worse with other tokens and amounts. Can anyone clue me into how to use the decimals to translate the amount I want to buy to the amount I need to send to the quote endpoint?

Let's call the decimals a token has `d` and the amount you want to buy `a`. Then the value you are looking for can be calculated by `a * 10^d`.
Example: You want to buy 50 USDC (`a = 50`) and USDC has 6 decimals (`d = 6`). The amount is `50 * 10^6 = 50000000`.