Format the numericInput in R with rounding but not change the actural value

I am wondering if it is possible to round the number to the input field of the numericInput but not change the true value. The ideal behavior of the input field would be similar to the cells in Excel spreadsheet as the users can format the cell value appearance, but the underlying numeric value is the original form. I found this Stack Overflow post "" describing the same question. For now, all the answers in the Stack Overflow post suggested that it is necessary to create two values. One is rounded, while the other one is not. Some people suggested that it should be a feature request to the Shiny team at RStudio. I would be grateful if someone can provide some answers or insights for this question.

You can change the number of digits shown when printing numbers with the digits option.

# [1] 7
# [1] 3.141593
options(digits = 2)
# [1] 3.1

Thanks for your response. But adding options(digits = 2) seems not affecting the input value of the numericInput.

Please see the following R script as an example. When running it as a Shiny app, I would like to see the numericInput "C"'s value as rounded such as 0.67, but the actual value is still 0.66666....


   # Define UI
      ui <- fluidPage(
      numericInput(inputId = "A", "Number A", value = 2),
      numericInput(inputId = "B", "Number B", value = 3),
      numericInput(inputId = "C", "Number C [A/B]", value = 1)

    # Server logic
    server <- function(input, output, session){
        req(input$A, input$B)
        num_C <- input$A/input$B
          inputId = "C",
          session = session,
          value = num_C

# Complete app with UI and server components
shinyApp(ui, server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.