Hide irrelevant decimal fractional part of numbers in spreadsheets

Is there any way to format numbers in 123/Excel-compatible spreadsheet applications, Google Spreadsheets in particular, in a way that hides the fractional part and the preceding decimal separator (i.e. dot or comma depending on locale) if it is zero (i.e. the number is an integer)?

123

  • 0.0 → 123.0
  • 0.# → 123. this is the closest I get
  • 0.? → 123.␠
  • 0_.0 → 123 0
  • 0_.# → 123 
  • 0_.? → 123 ␠

1.23

  • 0.0% → 123.0%
  • 0.#% → 123.%
  • 0.?% → 123. %
  • 0_.0% → 123 0%
  • 0_.#% → 123 %
  • 0_.?% → 123  %

I know that one can format positive, negative and zero-value numbers separately with semicolons: +0.0%;−0.0%;±0_?%