I'm having a uint
as 3123456
, and I want to get 123456
as number (ideally uint
), i.e. with the first digit stripped.I know I could parse it as a string
, remove the leading character, and convert it back:
func (id *MyID) Scan(v any) (err error) { asBytes, ok := v.([]byte) ... myDBNumber := binary.LittleEndian.Uint64(asBytes) // the field is of type BINARY in the db myDBNumberStr := strconv.Itoa(int(myDBNumber)) myDBNumberWithoutPrefix, err := strconv.Atoi(myDBNumberStr[1:]) ...}
Since I'm using this logic in an sql.Scanner
to parse IDs, I'm wondering whether there's a way where this parsing back and forward can be avoided, to improve the performance (or at least to compare the performance).