Detecting the Time Unit from `timescale

Hi,

Is there any way to detect the timeunit from `timescale

For Example, I have a generic code like this where some $display is there some string in needs to change as per the timescale.

`timescale 1ns/1ns
module test();
realtime var_1;
initial begin
#10;
if(detect_timescale == 1ns) begin
suffix=e-9;
end
var_1 = $realtime;
$display("var_1=%f%s",var_1,suffix);
end
endmodule

I dont want to use %t since I need to change it manually each time when I am running with different timescale.
My aim is to convert the time captured in var_1 to seconds regardless of the unit Need some operation to perform that.

In reply to rr2007:

Please ignore the arrow anti-pattern, basically you can try to cast to int to get the time unit

`timescale 1ns/1fs

module test;
  
  initial 
    begin
      if (int'(1us) == 1) begin 
        $display("It's us");
      end 
      else begin
        if (int'(1ns) == 1) begin
          $display("It's ns");
        end
        else begin
          if (int'(1ps) == 1) begin 
            $display("It's ps");
          end
          else begin
            if (int'(1fs) == 1) $display("It's fs");
          end
        end
      end
    end  
endmodule

It gives

# KERNEL: It's ns

If the time unit matches the value in the cast then the expression int’(1[timeunit]) == 1 will become true.

HTH,

-R

In reply to rr2007:

$realtime/1s gives you the time in seconds, regardless of the current timescalse. But only as precise as the current time precision.