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?