Figured out float formatting

I can't believe I didn't find out earlier about rounding down floating
point numbers with just two characters when instead of building an
entire function
This commit is contained in:
raul 2024-01-24 21:47:45 +01:00
parent 41f0d4a1f8
commit 114ba0c417
2 changed files with 17 additions and 9 deletions

3
partidos-apuestas/go.mod Normal file
View File

@ -0,0 +1,3 @@
module partidos-apuestas
go 1.21.6

View File

@ -4,14 +4,15 @@ package main
import (
"fmt"
"math"
//"math")
)
func roundFloat(numero float64, precision uint) float64 {
var radio = math.Pow(10, float64(precision))
var resultado = math.Round(numero*radio) / radio
return resultado
}
// This is dumb
// func roundFloat(numero float64, precision uint) float64 {
// var radio = math.Pow(10, float64(precision))
// var resultado = math.Round(numero*radio) / radio
// return resultado
// }
const IVA float64 = 1.1
@ -55,8 +56,12 @@ func main() {
}
var precioFinal float64 = costeFijo + impuestoPartidos + impuestoApuestas
var precioFinalMasIVA float64 = roundFloat(precioFinal*IVA, 2)
// var precioFinalMasIVA float64 = roundFloat(precioFinal*IVA, 2)
var precioFinalMasIVA float64 = precioFinal * IVA
fmt.Printf("\nLa factura del mes costará %.2f€!\n", precioFinal)
fmt.Printf("La factura del mes incluyendo IVA costará %.2f€!\n", precioFinalMasIVA)
fmt.Printf("\nLa factura del mes costará %v€!\n", precioFinal)
fmt.Printf("La factura del mes incluyendo IVA costará %v€!\n", precioFinalMasIVA)
// OH MY LORD, I DON'T NEED A DAMN FUNCTION JUST TO ROUND NUMBERS DOWN, I CAN
// LITERALLY JUST FORMAT TO FLOAT AND WRITE .$num BETWEEN % AND f
// I am the world's biggest dumbass
}