Going insane over Token pricing

I am kind of new at coding smart contracts. For the past week I have been going completely insane trying to set a price for a token.

Token has 2 decimals and I want the cost to be 0.001 ETH. No matter what I do is working. I have googled and read forums and seen people having the same problem, but I have never seen anyone getting a straight answer. So please don’t just tell me to google it, because I have.

The contract uses rate

// How many token units a buyer gets per wei.
// The rate is the conversion between wei and the smallest and indivisible token unit.
// So, if you are using a rate of 1 with a ERC20Detailed token with 3 decimals called TOK
// 1 wei will give you 1 unit, or 0.001 TOK.
uint256 private _rate;

But if I set the rate in wei I’m getting several billion tokens for 0.001 ETH. I have tried things like setting the price in TBNB but that isn’t accepted. I have tried everything in SafeMath, and I have tried everything I can find in this forum and in docs.

Please don’t answer by telling me to learn som new math I never even heard about. I just want the answer, and then I can figure it out later.

I supposed it was bound to happen. I found a solution 5 minutes after I finally decided to ask. I’m sure it’s not the “right way” but it works. I hope this can help someone else.

`````` /**
* @dev Override to extend the way in which ether is converted to tokens.
*
* @return Number of tokens that can be purchased with the specified uint256 c
*/
function _getTokenAmount(uint256 weiAmount) internal view returns (uint256) {
return _rate.div(weiAmount);

``````
`````` // Create the PupperCoinSale and tell it about the token, set the goal, and set the open and close times to now and (now + 24 weeks):
PupperCoinSale token_sale = new PupperCoinSale(100000000000000000 wei, wallet, token, goal);
You may not be taking the token decimals into account. When you see several billion tokens you need to remove a number of zeroes based on how many `decimals` your token has.