2

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

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.