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 6208131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:45:19+00:00 2026-05-24T05:45:19+00:00

I have a field in my admin page that I’d like to display in

  • 0

I have a field in my admin page that I’d like to display in Scientific Notation.

Right now it displays something ugly like this. How can I display this as 4.08E+13?

enter image description here

Right now I’m using a standard Decimal field in the model.

Any advice is greatly appreciated.

I’m on Django 1.2.

  • 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-24T05:45:19+00:00Added an answer on May 24, 2026 at 5:45 am

    Well, here’s a work around since I can’t figure out how to do this within the Django Python code. I have the admin pages run some custom javascript to do the conversion after the page is loaded.

    Details:

    Create this javascript file called “decimal_to_sci_not.js” and place it in your media directory:

    /*
    Finds and converts decimal fields > N into scientific notation.
    */
    
    THRESHOLD = 100000;
    PRECISION = 3;
    
    function convert(val) {
        // ex. 100000 -> 1.00e+5
        return parseFloat(val).toPrecision(PRECISION);
    }
    
    function convert_input_fields() {
        var f_inputs = django.jQuery('input');
        f_inputs.each(function (index, domEl) {
            var jEl = django.jQuery(this);
            var old_val = parseFloat(jEl.val());
            if (old_val >= THRESHOLD) {
               jEl.val(convert(old_val));
            }
        });
    }
    
    function convert_table_cells() {
        //Look through all td elements and replace the first n.n number found inside
        //if greater than or equal to THRESHOLD
        var cells = django.jQuery('td');
        var re_num = /\d+\.\d+/m; //match any numbers w decimal
        cells.each(function (index, domEl) {
            var jEl = django.jQuery(this);
            var old_val_str = jEl.html().match(re_num);
            var old_val = parseFloat(old_val_str);
            if (old_val >= THRESHOLD) {
               jEl.html(jEl.html().replace(old_val_str,convert(old_val)));
            }
        });
    }
    
    django.jQuery(document).ready( function () {
        convert_input_fields();
        convert_table_cells();
    });
    

    Then update your admin.py code classes to include the javascript file:

    class MyModel1Admin(admin.ModelAdmin):
    
        class Media:
            js = ['/media/decimal_to_sci_not.js']
    
    admin.site.register(MyModel1,MyModel1Admin)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that lets an admin user register a new user, by
I have a text field in a form_tag on my index page that should
I have field that it's not a key (it's text) and I want to
I have field like a_b_c_d I want as the output a b c_d, this
I have field X that contains text with spaces in the end of the
I have a field in my database called 'Stock'. It displays how many items
I have a field on my User model that is protected because it determines
I have something like: MEDIA_ROOT = '/home/httpd/foo/media/' MEDIA_URL = 'http://www.example.org/media/' (...) file = models.FileField(upload_to='test')
I have 2 pages: admin.php and admin_index.php. I have a username and password field
I'm loading a simple page using: $.get('../admin/login.php', function(data) { $('#box-contents').html(data); }); Now, on this

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.