1package numfmt23// Entered keeps the first 15 significant digits of a number written in4// decimal (digits, a point, an exponent) and makes the digits after them5// zeros, as Sheets and Excel do with a number typed into a formula:6// =123456789012345678 is 123456789012345000. Text with no more than 157// digits comes back as it is. Numbers typed into cells keep every digit,8// as files and imports write them with 17 to round-trip.9func Entered(s string) string {10 sig := 011 for i := 0; i < len(s); i++ {12 switch c := s[i]; {13 case c == 'e' || c == 'E':14 return s15 case c < '0' || c > '9':16 case sig > 0 || c != '0':17 sig++18 if sig > 15 {19 return zeroDigits(s, i)20 }21 }22 }23 return s24}2526// zeroDigits makes the digits of s from i up to any exponent zeros.27func zeroDigits(s string, i int) string {28 b := []byte(s)29 for ; i < len(b) && b[i] != 'e' && b[i] != 'E'; i++ {30 if b[i] >= '1' && b[i] <= '9' {31 b[i] = '0'32 }33 }34 return string(b)35}