package main import ( "fmt" "math" ) func main() { price := int64(300 * 7) discountPercent := 95.19 discount := discountPercent / 100.0 amount := int64(math.Round(float64(price) * discount)) fmt.Printf("price_cents=%d discount=%.4f amount_cents=%d amount=%.2f\n", price, discount, amount, float64(amount)/100.0) couponPercent := 10.0 coupon := int64(math.Round(float64(amount) * (couponPercent / 100.0))) amount -= coupon fmt.Printf("coupon_percent=%.2f coupon_cents=%d amount_cents=%d amount=%.2f\n", couponPercent, coupon, amount, float64(amount)/100.0) feePercent := 5.0 fee := int64(math.Round(float64(amount) * (feePercent / 100.0))) total := amount + fee fmt.Printf("fee_percent=%.2f fee_cents=%d total_cents=%d total=%.2f\n", feePercent, fee, total, float64(total)/100.0) }