Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7039527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:48:33+00:00 2026-05-28T01:48:33+00:00

How do you force a float to display with all significant places / full

  • 0

How do you force a float to display with all significant places / full precision without scientific notation in Ruby?

Presently I convert a BigDecimal to Float, BigDecimal(0.000000001453).to_f, however this yields a resultant float of 1.453e-09. If I do something like "%14.12f" % BigDecimal("0.000000001453").to_f I get a string. In this case, however, a string as output is unacceptable as I need it as an actual numeric float without scientific notation.

— Edit—

Alright, let me give some context here, which will probably require a change of my original question.

I’m attempting to create a graph with Highstock & lazy_high_chart. Earlier today I was able to draw graphs just fine when the floats were emitting to the resultant js as full precision floats vs showing up in scientific notation. Hence I felt that the problem resides in this issue.

But after the few inputs I’m getting here, perhaps I need some further review of the source and my assumption is misplaced. I’ll let you decide:

@h = LazyHighCharts::HighChart.new('graph') do |f|
  hours_of_readings = 1
  reading_intervals = 1 #hour
  readings_per_hour = 60

  readings = ModelName.order("date DESC").select('data_readings.data2, data_readings.data1, data_readings.date').limit(hours_of_readings * readings_per_hour).all

  data1_and_date_series = Array.new
  data2_and_date_series = Array.new
  dates = Array.new

  # I have been thinking that the problem lies here in the "row.data1.to_f" and
  #   "row.data2.to_f" and thus this is the root of my initial question in terms 
  #   of it emitting scientific notation to the js output in the format of:
  #   [[1.0e-09], [1.04e-09],[9.4e-09], ... [3.68e-09]]
  data1_and_date_series = readings.map{|row| [(row.date.to_i * 1000), (row.data1.to_f if BigDecimal(row.data1) != BigDecimal("-1000.0"))] }
  data2_and_date_series = readings.map{|row| [(row.date.to_i * 1000), (row.data2.to_f if BigDecimal(row.data2) != BigDecimal("-1000.0"))] }


  f.series(
      :name => 'Data1',
      :data => data1_and_date_series,
      :pointStart => Time.now.to_i * 1000,
      :pointEnd => hours_of_readings.hours.ago.to_i * 1000,
      :pointInterval => reading_intervals.hour * 1000,
      :color => 'blue'
  )
  f.series(
      :name => 'Data2)',
      :data => data2_and_date_series,
      :pointStart => Time.now.to_i * 1000,
      :pointEnd => hours_of_readings.hours.ago.to_i * 1000,
      :pointInterval => reading_intervals.hour.to_i * 1000,
      :color => 'red'
  )

  f.chart({:defaultSeriesType=>"spline" })
  f.yAxis [
        {:title => { :text => "Label 1", :margin => 10} },
        {:title => { :text => "Label 2 (groups)"}, :opposite => true},
        {:max => 0},
        {:min => -0.000000001}
  ]
  f.options[:xAxis] = {
      :title => { :text => "Time"},
      :type => "datetime"
  }
  f.title(:text => "Title")
  f.legend(:align => 'right', :verticalAlign => 'top', :y => 75, :x => -50, :layout => 'vertical') # override the default values
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:48:33+00:00Added an answer on May 28, 2026 at 1:48 am

    The string representation and the actual value of a float are two different things.

    What you see on screen/print-out is always a string representation, be it in scientific notation or “normal” notation. A float is converted to its string representation by to_s, puts, "%.10f" % and others.

    The float value itself is independent of that. So your last sentence does not make much sense. The output is always a string.

    To enforce a certain float format in Rails’ to_json you can overwrite Float#encode_json, e.g.

    class ::Float
      def encode_json(opts = nil)
        "%.10f" % self
      end
    end
    

    Put this before your code above. Note that — depending on your actual values — you might need more sophisticated logic to produce reasonable strings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does Microsoft force an update down to all of its users of windows-update? Is
My basic question is: How can I force Hibernate to make float NULLable and
I need to display float as 1.00 1.50 1.55 1.60 The following is what
How can I force .b to shrink to fit next to .a without using
How can I force all items in a horizontal list (menu) to be the
Does Google force employees who have offers from Facebook to leave immediately?
I want to force the current execution line to a specific line in the
How do I force Python's print function to flush the buffered output to the
I'm looking to force my application to shut down, and return an Exit code.
How can I force the input's onchange script to run before the RangeValidator's script?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.