Can you expand on new named numeric types being added? Like is your project implementing new numeric types? If so, you would control them and you could always just implement the stringer interface:
type NewNumber int64
func (n NewNumber) String() string {
return "the number"
}
//... and then in your switch
default:
s = fmt.Sprint(v) // Default is to use stringer interface
And if you wanted more control you could just define and implement your own interface:
type NewNumber int64
type Formatter interface {
Format(base int) string
}
func (n NewNumber) Format(base int) string {
return strconv.FormatInt(int64(n), base)
}
// ... later in your switch statement
case Formatter:
s = v.Format(prec)
At any rate, I don’t think there’s a direct way to do what you want to do at the moment. See this issue and final comment: