TransWikia.com

Showing values in attribute table in scientific (exponential) notation in QGIS3

Geographic Information Systems Asked by Olha Marinich on July 26, 2021

One of my virtual field contains too big numbers like "5994865699857.456". I need to show those values in scientific/exponential mode like 5.99E+12. I didn’t find proper function in Field Calculator. I searched for solution among others questions but all questions address inverse problem – converting scientific view to number one, and I didn’t find a solution among answers.

Is there some trick in Field Calculator to solve the problem?

Edit: I’d like to see value in scientific notation in Feature Attributes form when I use "Identify Features" function.

Edit2: I also tried to create custom function:

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def fd_sci(value1, feature, parent):
    vtostring = str(value1)
    a = "{:.2e}".format(vtostring)
    return a

Then created a new virtual field using expression:
fd_sci("virtual_field_with_big_number")

But the result is NULL

One Answer

Eventually I found what works. Just no need to convert a value to string, and Output field type should be Decimal number (real):

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def fd_sci(value1, feature, parent):
    a = "{:.2e}".format(value1)
    return a

Answered by Olha Marinich on July 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP